How to Access Parent Iframe from JavaScript

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.

Access elements of parent window from iframe

I think the problem may be that you are not finding your element because of the "#" in your call to get it:

window.parent.document.getElementById('#target'); 

You only need the # if you are using jquery. Here it should be:

window.parent.document.getElementById('target'); 

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

How to get the parent iframe's parent iframe using JavaScript?

Use window.parent.parent to get the grandparent window. So you want:

window.parent.parent.document.body.style.backgroundColor = "red";

And if you want the top-most parent, no matter how many levels deep you are, you can use window.top. See

Find most upper parent window with javascript

Access parent object in JavaScript from iFrame/Window

Option 1

Your title mentions a child window. If you have a child window, and not an iframe, use this:

window.opener.events_data

Check out window.opener on MDN.

Option 2

Your code indicates that you're using an iframe. From an iframe, simply use parent:

parent.events_data;

Check out window.parent on MDN.


window.opener - Returns a reference to the window that opened this current window.

window.parent - When a window is loaded in an , , or , its parent is the window with the element embedding the window.

how to access iFrame parent page using jquery?

To find in the parent of the iFrame use:

$('#parentPrice', window.parent.document).html();

The second parameter for the $() wrapper is the context in which to search. This defaults to document.

Access container of parent iframe element (Iframe inside iframe)

Maybe this:

var outer = window.parent;

var mainWindow = outer.parent;

var container = mainWindow.document.getElementsByClassName('container')[0];

but dont forget that your iframes have to be on the same domain.



Related Topics



Leave a reply



Submit