Availability: |
| |||||||
Property/method value type: | String primitive | |||||||
JavaScript syntax: | - | myWindow.name | ||||||
- | myWindow.name = aString | |||||||
- | name | |||||||
- | name = aString | |||||||
- | window.open(aURL, aName, ...) | |||||||
HTML syntax: | <FRAME NAME="..."> Window.open(...) | |||||||
Argument list: | aName | A name for the window | ||||||
aString | A string value containing the new name for the window | |||||||
aURL | A URL to load into the window |
This name value can be used with the target attribute of the HTML <A> anchor tag or the <FORM> tag.
At version 1.0 of JavaScript this is a read-only property.
JavaScript version 1.1 introduces the capability of changing the name of a window and makes this property writable. This is particularly useful because the initial window has no name and cannot be targeted directly until it has. You can fix this with an onLoad handler.
The name of a window can be set when the window is created with the open() method. It is also assigned by the NAME="..." HTML tag attribute of a <FRAME> tag.
The example shows the window name being modified. Reload to see the persistence effect. Load another document and then load this script again to see how the name persists through intermediate document loads.
This is not the title text for the window.
Note that the name value persists through document loads and so you may need to be careful if you are using the name property in a document script. It might have been set by an earlier page. This also suggests that other window properties may be persistent between documents and might provide a way to pass messages between pages and maintain state during a session.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> document.write("***"+window.name+"<BR>"); window.name = "FRED"; document.write("***"+window.name+"<BR>"); </SCRIPT> </BODY> </HTML>
See also: | Frame object, IFRAME.name, NAME="...", Window object, Window.open() |
Prev | Home | Next |
Window.moveTo() | Up | Window.navigate() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |