How to get the source source of the iframe source page?

We accept our iframe input form code and place it on the website page. We want to see where someone came from if they landed on the page and entered their information into the form.

For example: our iframe is embedded in the page. The URL of this page is sent to Facebook. Someone clicks the link, lands on the page and enters their information into our iframe input form. Then we want to say that 1 referral came from Facebook.

We tried to use $ _SERVER ['HTTP_REFERER'], but that just returns the URL of the parent page where the iframe is embedded, which we don’t want. We need the actual referral URL to the parent page (in the example above it would be Facebook). Anyway, to get this information?

+6
source share
1 answer

Unfortunately, cross-domain security will block this information from you, since your iframe is not in the same domain as the parent page that implements it. You can check the referrer in your iframe, but it will give you the name of the page that implements it.

If you were in the same domain, you would have access to document.referrer in javascript and could get it through an iframe.

I have an idea for a solution.

If you used a script to embed an iframe in the parent page, you could do something like this.

 function createIFrame() { var ref = document.referrer; ifrm = document.createElement("iframe"); ifrm.setAttribute("src", "http://www.nba.com/?referrer="+ref); ifrm.style.width = 640+"px"; ifrm.style.height = 480+"px"; document.body.appendChild(ifrm); } createIFrame(); 

This will allow you in your iframe to read the referrer request line from your URL and send this information to your server. This will require you to pack some javascript with your widgets, but this may be the only solution for you.

JSFiddle - http://jsfiddle.net/7QbPN/

+9
source

Source: https://habr.com/ru/post/969593/


All Articles