How to access parent window object using jquery?

How to resolve parent window object using jquery?

This is my parent window variable, I want to set its value after closing the child window.

$('#serverMsg').html('some text here'); 
+42
javascript jquery
Jan 30 '10 at 9:50
source share
4 answers
 window.opener.$("#serverMsg") 
+72
Jan 30 '10 at
source share
β€” -

If you are in po-up mode and want to open an open window, use window.opener . The easiest way is to load jQuery into the parent window:

window.opener.$("#serverMsg").html // this uses jQuery in the parent window

or you can use the plain old document.getElementById to get the element and then expand it using jquery in the child window. The following should work (I have not tested it yet):

 element = window.opener.document.getElementById("serverMsg"); element = $(element); 

If you are in an iframe or frameset and want to access the parent frame, use window.parent instead of window.opener .

In accordance with a policy of the same origin, all this works without much effort, only if the child and parent windows are in the same domain.

+16
Jan 30
source share

or you can use a different approach:

 $( "#serverMsg", window.opener.document ) 
+7
Mar 29 '11 at 19:17
source share

Here is a more literal answer (the parent window, not the opener) to the original question, which can be used in the iframe if the domain name in the iframe matches the name of the parent window:

 window.parent.$("#serverMsg") 
0
Aug 05 '16 at 19:53 on
source share



All Articles