

Ask HN: How to get referrer source of iframe parent page? - jrod2121

I&#x27;m looking to place to iframe a form into a page, and when someone lands on that page and enters their information into the form, I want to grab the referrer source.<p>For example: I embed the iframe onto website.com&#x2F;contact. The URL of that page gets posted to Facebook. Someone clicks the link, lands on the page, and enters their information into form. I then want to be able to say, 1 referral came from Facebook.<p>I tried using $_SERVER[&#x27;HTTP_REFERER&#x27;], but this just returns the parent page URL of where the iframe form is embedded, which I don&#x27;t want. I want the actual URL of the referral to the parent page (in the example above, it would be Facebook). Is there anyway to grab this information?
======
LeBlanc
Do you have the ability to execute JS on the parent page? If so, the easiest
and most reliable way to do this is to use the postMessage API to send
document.referrer from the parent to the iframe.

[https://developer.mozilla.org/en-
US/docs/Web/API/Window.post...](https://developer.mozilla.org/en-
US/docs/Web/API/Window.postMessage)

------
NameNickHN
You'll need to pass the referrer as parameter of the iframe URL.

