Access Parent Url from Iframe

Access parent URL from iframe

You're correct. Subdomains are still considered separate domains when using iframes. It's possible to pass messages using postMessage(...), but other JS APIs are intentionally made inaccessible.

It's also still possible to get the URL depending on the context. See other answers for more details.

How to get the parent window URL from Iframe?

Try this inside the iframe. It will alert the parent window's location URL.

alert(document.referrer);

Access parent window from iframe (cross-domain)

If I were you I would check out window.postMessage. It may do what you want:

For reference see the following:

  • MDN - Window.postMessage
  • https://stackoverflow.com/a/3076648/296889 - see the Window.postMessage section


Related Topics



Leave a reply



Submit