[ACCEPTED]-how to access parent window object using jquery?-jquery

Accepted answer
Score: 78
window.opener.$("#serverMsg")

0

Score: 18

If you are in a po-up and you want to access 13 the opening window, use window.opener. The easiest would be if you 12 could load JQuery in the parent window as 11 well:

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

or you could use plain old document.getElementById to get 9 the element, and then extend it using the 8 jquery in your child window. The following 7 should work (I haven't tested it, though):

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

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

According to the Same Origin Policy, all 3 this works effortlessly only if both the 2 child and the parent window are in the same 1 domain.

Score: 11

or you can use another approach:

$( "#serverMsg", window.opener.document )

0

Score: 0

Here is a more literal answer (parent window 4 as opposed to opener) to the original question 3 that can be used within an iframe, assuming 2 the domain name in the iframe matches that 1 of the parent window:

window.parent.$("#serverMsg")

More Related questions