April 18, 2000 - Renaming the Current Window | WebReference

April 18, 2000 - Renaming the Current Window

Yehuda Shiran April 18, 2000
Renaming the Current Window
Tips: April 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

HTML doesn't provide a definition that assigns a name to the current window. Assigning a value to the window.name property (the name property of the window object) is the only way to set the name of the current window. Let's demonstrate it. The following code creates a simple button that sets the name of the window:

<FORM>
<INPUT TYPE="button" VALUE="Set Name to myWin" onClick="window.name = 'myWin'">
</FORM>

Now click the button:

Once you've clicked the button, the name of the current window becomes "myWin", and it remains the same unless we assign a different value to the name property. We can, for example, include links or forms in other windows that load in the current window by specifying TARGET="myWin". Click the following link to load a demonstration page in a new window:

Demonstration Page

If you previously set the name of the current window by clicking the button, the links in the new window should load in the current window. Here's the code for the links in the new window:

<A HREF="http://www.docjs.com/" TARGET="myWin">Home</A>
<A HREF="http://www.docjs.com/tips/" TARGET="myWin">Recent Tips</A>

For your convenience, use the following button to reset the name of the current window by setting its name property to an empty string (""):

You should be careful not to assign the same name to two different windows. If two windows are assigned the same name, the name ends up associated with one of the windows, and the other window's name is ignored.

Learn more about windows creation and usage in Tutorial 1, Working with Windows.