Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

Pass data between windows


The window from which a second window is created is referred to a the 'operner' of the
second window.

The first window can access the properties of the second window by using the window
object returned from the .open() method :

var newWindow = document.open ( " http://www.garybeene.com " , "newWin" )

After this code, the new window is named 'newWin' and the current window has a JavaScript
variable which is a reference to the new window and can be used to access the properties
and methods of the new window.


The child window can also access the first window by using its 'opener' property, which refers
to the parent window (the one that created the child window).

In the new window, use this code to create a variable reference to the parent window :

if (self.opener != null ) {
    var parentWindow = self.opener
}

Now, the parentWindow variable (that is contained in the child window) can access all of the
methods and properties of the parent window


Note :  an exception is that if the JavaScript in the two windows comes from different servers,
the JavaScript will not be able to communicate.