Kshitij Jain
Kshitij Jain

Reputation: 1793

How to access child window from parent window through javascript?

Suppose we open a popup through javascript when a link is clicked on parent window.

As everybody knows that parent window elements can be accessed from child window using the window.opener() function.

Is it possible to do exactly reverse ? Can parent window access the information about the child window ?

Upvotes: 5

Views: 27867

Answers (2)

niksvp
niksvp

Reputation: 5563

When you open a window through javascript's window.open() function it returns you a reference of the child window.

Using this reference you can access elements of the child window, required it complies with Same origin policy security requirements.

Upvotes: 6

Arpit Agrawal
Arpit Agrawal

Reputation: 891

You mean something like this:

a=window.open()
a.document.write("<div id='mydiv'>test</div>")
a.document.getElementById("mydiv")

Upvotes: 7

Related Questions