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
Chrome Desktop Notification Example
What Is Typescript and Why Would I Use It in Place of JavaScript
Group Objects by Multiple Properties in Array Then Sum Up Their Values
Please Explain the Use of JavaScript Closures in Loops
Recurring Events in Fullcalendar
Is the Underscore Prefix for Property and Method Names Merely a Convention
How to Post a X-Www-Form-Urlencoded Request Using Fetch
Regex for JavaScript to Allow Only Alphanumeric
Differencebetween Screenx/Y, Clientx/Y and Pagex/Y
JavaScript Closures VS. Anonymous Functions
Open Url in New Window with JavaScript
How to Get a Dom Element from a Jquery Selector
How to Perform a Dns Lookup (Hostname to Ip Address) Using Client-Side JavaScript