Knowledge Base Articles » KB100210: Referencing Windows in JavaScript.

As websites get more and more complex, with the use of pop-up windows to display information to the user, for example, the ability to refer to these windows explicitly in our scripts becomes crucial. Let's look at a likely case.

An important point to remember when opening new windows is the need to explicitly declare the new window name outside of the function that creates it. Below is an example of this (here we shall call the new window 'LaunchedWin').

var LaunchedWin
function OpenWin()
{   LaunchedWin ="LaunchedWin.html", "LaunchedWin",

We can now access this new window, and its contents, using the following syntax (we'll assume that the document in the new window contains a text field, 'newText', on a form called 'changeForm').


After opening this new window, you may need to refer to the original 'opener' window from a script in the new window. To achieve this we use 'window.opener' to return the document that opened the new window. For example, suppose we have opened our new window by calling our example function when clicking a button on a form called 'myForm'. From this newly created window we can refer to this form in the opening window as follows:


We can then extend this to reference any element on this form. Given that we have a text field on 'myForm' called 'oldText' we could then alter the text in this field like so:

window.opener.document.myForm.oldText.value = "new text goes here"