How to get the url of the parent page of an iframe without being in the same domain?

Asked

Viewed 1,281 times

1

I searched postMessage, but only found examples of iframe resizing.

I wonder if you have any way to get the URL of the main page where my iframe is inserted using this method or some other.

1 answer

1

You can use the following:

var parentURL = window != window.parent ? document.referrer : null;

When your page loads into an iframe, window is different from window.parent. In that case, document.referrer will have the URL of the page that uploaded your iframe.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.