April 18, 2000 - Renaming the Current Window
April 18, 2000|
Renaming the Current Window
Tips: April 2000
Yehuda Shiran, Ph.D.
nameproperty of the
windowobject) 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
nameproperty. 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:
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.