I researched postMessage, but I only found examples of iframe resizing.
I would like to know if there is any way to get the URL of the main page where my iframe is inserted using this or some other method.
I researched postMessage, but I only found examples of iframe resizing.
I would like to know if there is any way to get the URL of the main page where my iframe is inserted using this or some other method.
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 this case, document.referrer
will have the URL of the page that loaded its iframe
.