Objects

The following objects are available in JavaScript:
  • anchor
  • button
  • checkbox
  • Date
  • document
  • form
  • frame
  • hidden
  • history
  • link
  • location
  • Math
  • navigator
  • password
  • radio
  • reset
  • select
  • string
  • submit
  • text
  • textarea
  • window
  • NOTE: Each object topic indicates whether the object is part of the client (in Navigator), server (in LiveWire), or is common (built-in to JavaScript). Server objects are not included in this version of the documentation.


    anchor object (client)

    A piece of text identified as the target of a hypertext link.

    Syntax

    To define an anchor, use standard HTML syntax:

    <A NAME="anchorName"
       [HREF=locationOrURL]>
       anchorText
    </A>
    
    NAME="anchorName" specifies a tag that becomes an available hypertext target within the current document.
    HREF=locationOrURL identifies a destination anchor or URL.
    anchorText specifies the text to display at the anchor.

    Description

    You can reference the anchor objects in your code by using the anchors property of the document object. The anchors property is an array that contains an entry for each anchor in a document. See the anchors property.

    Properties

  • None.

    Methods

  • None.

    Event handlers

    None.

    Examples

    <A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A>

    See also the example for the anchors property.

    See also

  • link object
  • anchors property

    button object (client)

    A pushbutton on an HTML form.

    Syntax

    To define a button:

    <INPUT
       TYPE="button"
       NAME="buttonName"
       VALUE="buttonText"
       [onClick="handlerText"]>
    
    NAME="buttonName" specifies the name of the button object. You can access this value using the name property.
    VALUE="buttonText" specifies the label to display on the button face. You can access this value using the value property.

    To use a button object's properties and methods:

    1. buttonName.propertyName
    2. buttonName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    buttonName is the value of the NAME attribute of a button object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a button object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A button object is a form element and must be defined within a <FORM>...</FORM> tag.

    The button object is a custom button that you can use to perform an action you define. The button executes the script specified by its onClick event handler.

    Properties

  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    In the following example, myfunction() is a JavaScript function.

    <INPUT TYPE="button" VALUE="Calculate" NAME="calc_button" onClick="myfunction(this.form)">

    See also

  • form, reset, and submit objects

    checkbox object (client)

    A checkbox on an HTML form. A checkbox is a toggle switch that lets the user set a value on or off.

    Syntax

    To define a checkbox, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="checkbox"
       NAME="checkboxName"
       VALUE="checkboxValue"
       [CHECKED]
       [onClick="handlerText"]>
       textToDisplay
    
    NAME="checkboxName" specifies the name of the checkbox object. You can access this value using the name property.
    VALUE="checkboxValue" specifies a value that is returned to the server when the checkbox is selected and the form is submitted. This defaults to "on". You can access this value using the value property.
    CHECKED specifies that the checkbox is displayed as checked. You can access this value using the defaultChecked property.
    textToDisplay specifies the label to display beside the checkbox.

    To use a checkbox object's properties and methods:

    1. checkboxName.propertyName
    2. checkboxName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    checkboxName is the value of the NAME attribute of a checkbox object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a checkbox object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A checkbox object is a form element and must be defined within a <FORM>...</FORM> tag.

    Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded.

    Properties

  • checked lets you programatically check a checkbox
  • defaultChecked reflects the CHECKED attribute
  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example displays a group of four checkboxes that all appear checked by default.

    <B>Specify your music preferences (check all that apply):</B> <BR><INPUT TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B <BR><INPUT TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz <BR><INPUT TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues <BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED> New Age

    See also

  • form and radio objects

    Date object (common)

    Lets you work with dates and times.

    Syntax

    To create a Date object:

    1. dateObjectName = new Date()
    2. dateObjectName = new Date("month day, year hours:minutes:seconds")
    3. dateObjectName = new Date(year, month, day)
    4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)
    
    dateObjectName is either the name of a new object or a property of an existing object.
    month, day, year, hours, minutes, and seconds are string values for form 2 of the syntax. For forms 3 and 4, they are integer values.

    To use Date methods:

    dateObjectName.methodName(parameters)
    
    dateObjectName is either the name of an existing Date object or a property of an existing object..
    methodName is one of the methods listed below.

    Exceptions: The Date object's parse and UTC methods are static methods that you use as follows:

    Date.UTC(parameters)
    Date.parse(parameters)
    

    Description

    Form 1 of the syntax creates today's date and time. If you omit hours, minutes, or seconds from form 2 or 4 of the syntax, the value will be set to zero.

    The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since January 1, 1970 00:00:00.

    JavaScript does not have a date data type, but you can use the Date object and its methods to work with dates and times in your applications. The Date object has many methods for setting, getting, and manipulating dates.

    Properties

    None.

    Methods

  • getDate
  • getDay
  • getHours
  • getMinutes
  • getMonth
  • getSeconds
  • getTime
  • getTimeZoneoffset
  • getYear
  • parse
  • setDate
  • setHours
  • setMinutes
  • setMonth
  • setSeconds
  • setTime
  • setYear
  • toGMTString
  • toLocaleString
  • UTC

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    today = new Date() birthday = new Date("December 17, 1995 03:24:00") birthday = new Date(95,12,17) birthday = new Date(95,12,17,3,24,0)

    document object (client)

    Contains information on the current document.

    Syntax

    To define a document object, use standard HTML syntax:

    <BODY
       BACKGROUND="backgroundImage"
       BGCOLOR="backgroundColor"
       FGCOLOR="foregroundColor"
       LINK="unfollowedLinkColor"
       ALINK="activatedLinkColor"
       VLINK="followedLinkColor"
       [onLoad="handlerText"]
       [onUnload="handlerText"]>
    </BODY>
    
    BACKGROUND specifies an image that fills the background of the document.
    BGCOLOR, FGCOLOR, LINK, ALINK, and VLINK are color specifications expressed as a hexadecimal RGB triplet (in the format "rrggbb" or "#rrggbb") or as one of the string literals listed in Color Values.

    To use a document object's properties and methods:

    1. document.propertyName
    2. document.methodName(parameters)
    
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    The <BODY>...</BODY> tag encloses an entire document, which is defined by the current URL. The entire body of the document (all other HTML elements for the document) goes within the <BODY>...</BODY> tag.

    You can reference the anchors, forms, and links of a document by using the anchors, forms, and links properties. These properties are arrays that contain an entry for each anchor, form, or link in a document.

    Properties

  • alinkColor reflects the ALINK attribute
  • anchors is a reflection of all the anchors in a document
  • bgColor reflects the BGCOLOR attribute
  • cookie specifies a cookie
  • fgColor reflects the FGCOLOR attribute
  • forms is a reflection of all the forms in a document
  • lastModified reflects the date a document was last modified
  • linkColor reflects the LINK attribute
  • links is a reflection of all the links in a document
  • location reflects the complete URL of a document
  • referrer reflects the URL of the calling document
  • title reflects the contents of the <TITLE>...</TITLE> tag
  • vlinkColor reflects the VLINK attribute

    Methods

  • clear
  • close
  • open
  • write
  • writeln

    Event handlers

    None. The onLoad and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object.

    Examples

    The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors.

    DOC1.HTML, which defines the frames, contains the following code:

    <HTML> <HEAD> <TITLE>Document object example</TITLE> </HEAD> <FRAMESET COLS="30%,70%"> <FRAME SRC=doc2.html NAME="frame1"> <FRAME SRC=doc3.html NAME="frame2"> </FRAMESET> </HTML>

    DOC2.HTML, which defines the content for the first frame, contains the following code:

    <HTML> <SCRIPT> // Must set foreground color before layout document.fgColor="darkviolet" </SCRIPT> <BODY BGCOLOR="antiquewhite" LINK="fuchsia" ALINK="forestgreen" VLINK="navy"> <P><B>Some links</B> <LI><A HREF=doc3.html#numbers TARGET="frame2">Numbers</A> <LI><A HREF=doc3.html#colors TARGET="frame2">Colors</A> <LI><A HREF=doc3.html#musicTypes TARGET="frame2">Music types</A> <LI><A HREF=doc3.html#countries TARGET="frame2">Countries</A> </BODY> </HTML>

    DOC3.HTML, which defines the content for the second frame, contains the following code:

    <HTML> <SCRIPT> // Must set foreground color before layout document.fgColor="navy" </SCRIPT> <BODY BGCOLOR="oldlace" onLoad="alert('Hello, World.')"> <P><A NAME="numbers"><B>Some numbers</B></A> <LI>one <LI>two <LI>three <LI>four <LI>five <LI>six <LI>seven <LI>eight <LI>nine <P><A NAME="colors"><B>Some colors</B></A> <LI>red <LI>orange <LI>yellow <LI>green <LI>blue <LI>purple <LI>brown <LI>black <P><A NAME="musicTypes"><B>Some music types</B></A> <LI>R&B <LI>Jazz <LI>Soul <LI>Reggae <LI>Rock <LI>Country <LI>Classical <LI>Opera <P><A NAME="countries"><B>Some countries</B></A> <LI>Afghanistan <LI>Brazil <LI>Canada <LI>Finland <LI>India <LI>Italy <LI>Japan <LI>Kenya <LI>Mexico <LI>Nigeria </BODY> </HTML>

    See also

  • frame and window objects

    form object (client)

    Lets users input text and make choices from form objects such as checkboxes, radio buttons, and selection lists. You can also use a form to post data to or retrieve data from a server.

    Syntax

    To define a form, use standard HTML syntax with the addition of the onSubmit event handler:

    <FORM
       NAME="formName"
       TARGET="windowName"
       ACTION="serverURL"
       METHOD=GET | POST
       ENCTYPE="encodingType"
       [onSubmit="handlerText"]>
    </FORM>
    

    NAME="formName" specifies the name of the form object.

    TARGET="windowName" specifies the window that form responses go to. When you submit a form with a TARGET attribute, server responses are displayed in the specified window instead of the window that contains the form. windowName can be an existing window; it can be a frame name specified in a <FRAMESET> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a JavaScript expression (for example, it cannot be parent.frameName or windowName.frameName). Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the target property.

    ACTION="serverURL" specifies the URL of the server to which form field input information is sent. Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the action property.

    METHOD=GET | POST specifies how information is sent to the server specified by ACTION. GET (the default) appends the input information to the URL which on most receiving systems becomes the value of the environment variable QUERY_STRING. POST sends the input information in a data body which is available on stdin with the data length set in the environment variable CONTENT_LENGTH. Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the method property.

    ENCTYPE="encodingType" specifies the MIME encoding of the form: "application/x-www-form-urlencoded" or "multipart/form-data". Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the encoding property.

    To use a form object's properties and methods:

    1. formName.propertyName
    2. formName.methodName(parameters)
    3. forms[index].propertyName
    4. forms[index].methodName(parameters)
    
    formName is the value of the NAME attribute of a form object.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.
    index is an integer representing a form object.

    Description

    Each form in a document is a distinct object.

    You can reference the form objects in your code by using the form name or the forms property of the document object. The forms property is an array that contains an entry for each form in a document.

    You can reference a form's elements in your code by using the element's name (from the NAME="" attribute) or the elements property. The elements property is an array that contains an entry for each element (such as a checkbox, radio, or text object) in a form.

    Properties

  • action reflects the ACTION attribute
  • elements is a reflection of all the elements in a form
  • encoding reflects the ENCTYPE attribute
  • length reflects the number of elements on a form
  • method reflects the METHOD attribute
  • target reflects the TARGET attribute

    Methods

  • submit

    Event handlers

  • onSubmit

    Examples

    xxx to be supplied

    See also

  • elements and forms properties

    frame object (client)

    A window that can display multiple, independently scrollable frames on a single screen, each with its own distinct URL. Frames can point to different URLs and be targeted by other URLs, all within the same screen. A series of frames makes up a page.

    Syntax

    To define a frame object, use standard HTML syntax. The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object:

    <FRAMESET
       ROWS="rowHeightList"
       COLS="columnWidthList"
       [onLoad="handlerText"]
       [onUnload="handlerText"]>
       [<FRAME SRC="locationOrURL" NAME="frameName">]
    </FRAMESET>
    
    ROWS="rowHeightList" is a comma-separated list of values specifying the row-height of the frame. An optional suffix defines the units. Default units are pixels.
    COLS="columnWidthList" is a comma-separated list of values specifying the column-width of the frame. An optional suffix defines the units. Default units are pixels.
    FRAME defines a frame.
    SRC="locationOrURL" specifies the URL of the document to be displayed in the frame.
    NAME="frameName" specifies a name to be used as a target of hyperlink jumps.

    To use a frame object's methods:

    1. [windowReference.]frameName.methodName(parameters)
    2. [windowReference.]frames[index].methodName(parameters)
    
    windowReference is a variable windowVar from a window definition (see window object), or one of the synonyms top or parent.
    frameName is the value of the NAME attribute in the <FRAME> tag of a frame object.
    methodName is one of the methods listed below.
    index is an integer representing a frame object.

    Description

    The <FRAMESET> tag is used in an HTML document whose sole purpose is to define the layout of frames that make up a page. Each frame is a window object.

    You can reference the frame objects in your code by using the frames property of the window object. The frames property is an array that contains an entry for each frame in a window containing a <FRAMESET> tag.

    If a <FRAME> tag contains SRC and NAME attributes, you can refer to that frame from a sibling frame by using parent.frameName or parent.frames[index]. For example, if the fourth frame in a set has NAME="homeFrame", sibling frames can refer to that frame using parent.homeFrame or parent.frames[3].

    Properties

  • frames is a reflection of all the frames in a window
  • parent is a synonym for the windowName argument and refers to a window containing a frameset
  • self is a synonym for the windowName argument and refers to the current window
  • top is a synonym for the windowName argument and refers to the top-most Navigator window
  • window is a synonym for the windowName argument and refers to the current window

    Methods

  • alert
  • close
  • confirm
  • open
  • prompt
  • setTimeout
  • clearTimeout

    Event handlers

    None. The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object.

    Examples

    The following example creates two windows, each with four frames. In the first window, the first frame contains pushbuttons that change the background colors of the frames in both windows.

    FRAMSET1.HTML, which defines the frames for the first window, contains the following code:

    <HTML> <HEAD> <TITLE>Frames and Framesets: Window 1</TITLE> </HEAD> <FRAMESET ROWS="50%,50%" COLS="40%,60%" onLoad="alert('Hello, World.')"> <FRAME SRC=framcon1.html NAME="frame1"> <FRAME SRC=framcon2.html NAME="frame2"> <FRAME SRC=framcon2.html NAME="frame3"> <FRAME SRC=framcon2.html NAME="frame4"> </FRAMESET> </HTML>

    FRAMSET2.HTML, which defines the frames for the second window, contains the following code:

    <HTML> <HEAD> <TITLE>Frames and Framesets: Window 2</TITLE> </HEAD> <FRAMESET ROWS="50%,50%" COLS="40%,60%"> <FRAME SRC=framcon2.html NAME="frame1"> <FRAME SRC=framcon2.html NAME="frame2"> <FRAME SRC=framcon2.html NAME="frame3"> <FRAME SRC=framcon2.html NAME="frame4"> </FRAMESET> </HTML>

    FRAMCON1.HTML, which defines the content for the first frame in the first window, contains the following code:

    <HTML> <BODY> <A NAME="frame1"><H1>Frame1</H1></A> <P><A HREF="framcon3.htm" target=frame2>Click here</A> to load a different file into frame 2. <SCRIPT> window2=open("framset2.htm","secondFrameset") </SCRIPT> <FORM> <P><INPUT TYPE="button" VALUE="Change frame2 to teal" onClick="parent.frame2.document.bgColor='teal'"> <P><INPUT TYPE="button" VALUE="Change frame3 to slateblue" onClick="parent.frames[2].document.bgColor='slateblue'"> <P><INPUT TYPE="button" VALUE="Change frame4 to darkturquoise" onClick="top.frames[3].document.bgColor='darkturquoise'"> <P><INPUT TYPE="button" VALUE="window2.frame2 to violet" onClick="window2.frame2.document.bgColor='violet'"> <P><INPUT TYPE="button" VALUE="window2.frame3 to fuchsia" onClick="window2.frames[2].document.bgColor='fuchsia'"> <P><INPUT TYPE="button" VALUE="window2.frame4 to deeppink" onClick="window2.frames[3].document.bgColor='deeppink'"> </FORM> </BODY> </HTML>

    FRAMCON2.HTML, which defines the content for the remaining frames, contains the following code:

    <HTML> <BODY> <P>This is a frame. </BODY> </HTML>

    FRAMCON3.HTML, which is referenced in a link object in FRAMCON1.HTML, contains the following code:

    <HTML> <BODY> <P>This is a frame. What do you think? </BODY> </HTML>

    See also

  • document and window objects
  • frames property

    hidden object (client)

    A text object that is suppressed from form display on an HTML form.

    Syntax

    To define a hidden object:

    <INPUT
       TYPE="hidden"
       NAME="hiddenName"
       [VALUE="textValue"]>
    
    NAME="hiddenName" specifies the name of the hidden object. You can access this value using the name property.
    VALUE="textValue" specifies the initial value of the hidden object.

    To use a hidden object's properties:

    1. hiddenName.propertyName
    2. formName.elements[index].propertyName
    
    hiddenName is the value of the NAME attribute of a hidden object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a hidden object on a form.
    propertyName is one of the properties listed below.

    Description

    A hidden object is a form element and must be defined within a <FORM>...</FORM> tag.

    You can use hidden objects instead of cookies for client/server communication.

    Properties

  • name reflects the NAME attribute
  • value reflects the current value of the hidden object

    Methods

    None.

    Event handlers

    None.

    Examples

    The following example uses a hidden object to store the value of the last object the user clicked. The form contains a "Display hidden value" button that the user can click to display the value of the hidden object in an Alert dialog box. <HTML> <HEAD> <TITLE>Hidden object example</TITLE> </HEAD> <BODY> <B>Click some of these objects, then click the "Display value" button <BR>to see the value of the last object clicked.</B> <FORM NAME="form1"> <INPUT TYPE="hidden" NAME="hiddenObject" VALUE="None"> <P> <INPUT TYPE="button" VALUE="Click me" NAME="button1" onclick="document.form1.hiddenObject.value=this.value"> <P> <INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" onClick="document.form1.hiddenObject.value=this.value"> Soul and R&B <INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz" onClick="document.form1.hiddenObject.value=this.value"> Jazz <INPUT TYPE="radio" NAME="musicChoice" VALUE="classical" onClick="document.form1.hiddenObject.value=this.value"> Classical <P> <SELECT NAME="music_type_single" onFocus="document.form1.hiddenObject.value=this.options[this.selectedIndex].text"> <OPTION SELECTED> Red <OPTION> Orange <OPTION> Yellow </SELECT> <P><INPUT TYPE="button" VALUE="Display hidden value" NAME="button2" onClick="alert('Last object clicked: ' + document.form1.hiddenObject.value)"> </FORM> </BODY> </HTML>

    See also

  • cookie property

    history object (client)

    Contains information on the URLs that the client has visited within a window. This information is stored in a history list, and is accessible through the Navigator's Go menu.

    Syntax

    To use a history object:

    1. history.propertyName
    2. history.methodName(parameters)
    
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    The history object is a linked list of URLs the user has visited, as shown in the Navigator's Go menu.

    Properties

  • length reflects the number of entries in the history object

    Methods

  • back
  • forward
  • go

    Event handlers

    None.

    Examples

    The following example goes to the URL the user visited three clicks ago in the current window.

    history.go(-3)

    You can use the history object with a specific window or frame. The following example causes window2 to go back one item in its window (or session) history:

    window2.history.back()

    The following example causes the second frame in a frameset to go back one item:

    parent.frames[1].history.back()

    The following example causes the frame named frame1 in a frameset to go back one item:

    parent.frame1.history.back()

    The following example causes the frame named frame2 in window2 to go back one item:

    window2.frame2.history.back()

    See also

  • location object

    link object (client)

    A piece of text identified as a hypertext link. When the user clicks the link text, the link hypertext reference is loaded into its target window.

    Syntax

    To define a link, use standard HTML syntax with the addition of the onClick and onMouseOver event handlers:

    <A [NAME="anchorName"]
       HREF=locationOrURL
       TARGET="windowName"
       [onClick="handlerText"]
       [onMouseOver="handlerText"]>
       linkText
    </A>
    
    NAME="anchorName" specifies a tag that becomes an available hypertext target within the current document.
    HREF=locationOrURL identifies a destination anchor or URL.
    TARGET="windowName" specifies the window that the link is loaded into. windowName can be an existing window; it can be a frame name specified in a <FRAMESET> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a JavaScript expression (for example, it cannot be parent.frameName or windowName.frameName).
    linkText is rendered as a hypertext link to the URL.

    To use a link object's properties:

    document.links[index].propertyName
    
    index is an integer representing a link object.
    propertyName is one of the properties listed below.

    Description

    Each link object is a location object.

    You can reference the link objects in your code by using the links property of the document object. The links property is an array that contains an entry for each link in a document.

    When you specify a URL, you can use JavaScript statements in addition to using standard URL formats. The following list shows the syntax for specifying some of the most common types of URLs.
    URL typeProtocolExample
    JavaScript codejavascript:javascript:history.go(-1)
    World Wide Webhttp://http://www.netscape.com/
    Filefile://file:///javascript/methods.html
    FTPftp://ftp://ftp.mine.com/home/mine
    MailTomailto:mailto:info@netscape.com
    Gophergopher://gopher.myhost.com

    Properties

  • target reflects the TARGET attribute

    Methods

    None.

    Event handlers

  • onClick
  • onMouseOver

    Examples

    The following example creates a hypertext link to an anchor named javascript_intro.

    <A HREF="#javascript_intro">Introduction to JavaScript</A>

    The following example creates a hypertext link to an anchor named numbers in the file DOC3.HTML in the window window2. If window2 does not exist, it is created.

    <LI><A HREF=doc3.html#numbers TARGET="window2">Numbers</A>

    The following example creates a hypertext link to a URL.

    <A HREF="http://www.netscape.com">Netscape Home Page</A> The following example takes the user back x entries in the history list: <A HREF="javascript:history.go(-1 * x)">Click here</A>

    See also

  • anchor object
  • links property

    location object (client)

    Contains information on the current URL.

    Syntax

    To use a location object:

    [windowReference.]location.propertyName
    
    windowReference is a variable windowVar from a window definition (see window object), or one of the synonyms top or parent.
    propertyName is one of the properties listed below.

    Description

    The location object represents a complete URL. Each property of the location object represents a different portion of the URL.

    The following diagram of a URL shows the relationships between the location properties:

    protocol//hostname:port pathname search hash

    protocol represents the beginning of the URL, up to and including the first colon.
    hostname represents the domain name or IP address of a network host.
    port represents the port number to connect to.
    pathname represents the url-path portion of the URL.
    search represents any query information in the URL, beginning with a question mark.
    hash represents an anchor name fragment in the URL, beginning with a hash mark (#).

    The location object has two other properties not shown in the diagram above:

    href represents a complete URL.
    host represents the concatenation hostname:port.

    The location object is contained by the window object and is within its scope. If you reference a location object without specifying a window, the location object represents the current location. If you reference a location object and specify a window name, for example, windowReference.location.propertyName, the location object represents the location of the specified window.

    Do not confuse the location object with the location property of the document object. You cannot change the value of the location property (document.location), but you can change the value of the location object's properties (window.location.propertyName). document.location is a string-valued property that usually matches what window.location is set to when you load the document, but redirection may change it.

    Properties

  • hash specifies an anchor name in the URL
  • host specifies the hostname:port portion of the URL
  • hostname specifies the domain name or IP address of a network host
  • href specifies the entire URL
  • pathname specifies the url-path portion of the URL
  • port specifies the port number
  • protocol specifies the beginning of the URL, including the colon
  • search specifies a query

    Methods

    None.

    Event handlers

    None.

    Examples

    The following example sets the URL of the current window to the Netscape home page:

    window.location.protocol="http://home.netscape.com/"

    The following example sets the URL of a frame named frame2 to the Sun home page:

    parent.frame2.location.protocol="http://www.sun.com/"

    See also the example for the anchors property.

    See also

  • history object
  • location property

    Math object (common)

    A built-in object that has properties and methods for mathematical constants and functions. For example, the Math object's PI property has the value of pi.

    Syntax

    To use a Math object:

    1. Math.propertyName
    2. Math.methodName(parameters)
    
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    You reference the constant PI as Math.PI. Constants are defined with the full precision of real numbers in JavaScript.

    Similarly, you reference Math functions as methods. For example, the sine function is Math.sin(argument), where argument is the argument.

    It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example,

    with (Math) {
       a = PI * r*r
       y = r*sin(theta)
       x = r*cos(theta)
    }
    

    Properties

  • E
  • LN10
  • LN2
  • PI
  • SQRT1_2
  • SQRT2

    Methods

  • abs
  • acos
  • asin
  • atan
  • ceil
  • cos
  • exp
  • floor
  • log
  • max
  • min
  • pow
  • random
  • round
  • sin
  • sqrt
  • tan

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    See the examples for the individual properties and methods.


    navigator object (client)

    Contains information about the version of Navigator in use.

    Syntax

    To use a navigator object:

    navigator.propertyName
    
    propertyName is one of the properties listed below.

    Description

    Use the navigator object to determine which version of the Navigator your users have.

    Properties

  • appCodeName specifies the code name of the browser
  • appName specifies the name of the browser
  • appVersion specifies version information for the Navigator
  • userAgent specifies the user-agent header

    Methods

  • None.

    Event handlers

    None.

    Examples

    See the examples for the individual properties.

    See also

  • link object
  • anchors property

    password object (client)

    A text field on an HTML form that conceals its value by displaying asterisks (*). When the user enters text into the field, asterisks (*) hide anything entered from view.

    Syntax

    To define a password object, use standard HTML syntax:

    <INPUT
       TYPE="password"
       NAME="passwordName"
       [VALUE="textValue"]
       SIZE=integer>
    
    NAME="passwordName" specifies the name of the password object. You can access this value using the name property.
    VALUE="textValue" specifies the initial value of the password object. You can access this value using the defaultValue property.
    SIZE=integer specifies the number of characters the password object can accommodate without scrolling.

    To use a password object's properties and methods:

    1. passwordName.propertyName
    2. passwordName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    passwordName is the value of the NAME attribute of a password object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a password object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A password object is a form element and must be defined within a <FORM>...</FORM> tag.

    Properties

  • defaultValue reflects the VALUE attribute
  • name reflects the NAME attribute
  • value reflects the current value of the password object's field

    Methods

  • focus
  • blur
  • select

    Event handlers

    None.

    Examples

    <B>Password:</B> <INPUT TYPE="password" NAME="password" VALUE="" SIZE=25>

    See also

  • form and text objects

    radio object (client)

    A set of radio buttons on an HTML form. A set of radio buttons lets the user choose one item from a list.

    Syntax

    To define a set of radio buttons, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="radio"
       NAME="radioName"
       VALUE="buttonValue"
       [CHECKED]
       [onClick="handlerText"]>
       textToDisplay
    
    NAME="radioName" specifies the name of the radio object. All radio buttons in a group have the same NAME attribute. You can access this value using the name property.
    VALUE="buttonValue" specifies a value that is returned to the server when the radio button is selected and the form is submitted. This defaults to "on". You can access this value using the value property.
    CHECKED specifies that the radio button is selected. You can access this value using the defaultChecked property.
    textToDisplay specifies the label to display beside the radio button.

    To use a radio button's properties and methods:

    1. radioName[index1].propertyName
    2. radioName[index1].methodName(parameters)
    3. formName.elements[index2].propertyName
    4. formName.elements[index2].methodName(parameters)
    
    radioName is the value of the NAME attribute of a radio object.
    index1 is an integer representing a radio button in a radio object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index2 is an integer representing a radio button on a form. The elements array contains an entry for each radio button in a radio object.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A radio object is a form element and must be defined within a <FORM>...</FORM> tag.

    All radio buttons in a radio button group use the same name property. To access the individual radio buttons in your code, follow the object name with an index starting from zero, one for each button the same way you would for an array such as forms: document.forms[0].radioName[0] is the first, document.forms[0].radioName[1] is the second, etc.

    Properties

  • checked lets you programatically select a radio button
  • defaultChecked reflects the CHECKED attribute
  • length reflects the number of radio buttons in the radio object
  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example defines a radio button group to choose among three music catalogs. Each radio button is given the same name, NAME="musicChoice", forming a group of buttons for which only one choice can be selected. The example also defines a text field that defaults to what was chosen via the radio buttons but that allows the user to type a nonstandard catalog name as well. The onClick event handler sets the catalog name input field when the user clicks a radio button.

    <INPUT TYPE="text" NAME="catalog" SIZE="20"> <INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b" onClick="musicForm.catalog.value = 'soul-and-r&b'"> Soul and R&B <INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz" onClick="musicForm.catalog.value = 'jazz'"> Jazz <INPUT TYPE="radio" NAME="musicChoice" VALUE="classical" onClick="musicForm.catalog.value = 'classical'"> Classical

    See also

  • checkbox, form, and select objects

    reset object (client)

    A reset button on an HTML form. A reset button resets all elements in a form to their defaults.

    Syntax

    To define a reset button, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="reset"
       NAME="resetName"
       VALUE="buttonText"
       [onClick="handlerText"]>
    
    NAME="resetName" specifies the name of the reset object. You can access this value using the name property.
    VALUE="buttonText" specifies the text to display on the button face. You can access this value using the value property.

    To use a reset object's properties and methods:

    1. resetName.propertyName
    2. resetName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    resetName is the value of the NAME attribute of a reset object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a reset object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A reset object is a form element and must be defined within a <FORM>...</FORM> tag.

    Properties

  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example displays a text object with the default value "CA". If the user types a different state abbreviation in the text object and then clicks the Clear Form button, the original value of "CA" is restored.

    <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><INPUT TYPE="reset" VALUE="Clear Form">

    See also

  • button, form, and submit objects

    select object (client)

    A selection list or scrolling list on an HTML form. A selection list lets the user choose one item from a list. A scrolling list lets the user choose one or more items from a list.

    Syntax

    To define a select object, use standard HTML syntax with the addition of the onBlur, onChange, and onFocus event handlers:

    <SELECT
       NAME="selectName"
       [SIZE="integer"]
       [MULTIPLE]
       [onBlur="handlerText"]
       [onChange="handlerText"]
       [onFocus="handlerText"]>
       <OPTION VALUE="optionValue" [SELECTED]> textToDisplay [ ... <OPTION> textToDisplay]
    </SELECT>
    
    NAME="selectName" specifies the name of the select object. You can access this value using the name property.
    SIZE="integer" specifies the number of options visible when the form is displayed.
    MULTIPLE specifies that the select object is a scrolling list (not a selection list).
    OPTION specifies a selection element in the list. You can access the options using the options property.
    VALUE="optionValue" specifies a value that is returned to the server when the option is selected and the form is submitted. You can access this value using the value property.
    SELECTED specifies that the option is selected by default. You can access this value using the defaultSelected property.
    textToDisplay specifies the text to display in the list. You can access this value using the text property.

    To use a select object's properties and methods:

    1. selectName.propertyName
    2. selectName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    selectName is the value of the NAME attribute of a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a select object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    To use an option's properties:

    1. selectName.options[index1].propertyName
    2. formName.elements[index2].options[index1].propertyName
    
    selectName is the value of the NAME attribute of a select object.
    index1 is an integer representing an option in a select object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index2 is an integer representing a select object on a form.
    propertyName is one of the properties listed below.

    Description

    A select object is a form element and must be defined within a <FORM>...</FORM> tag.

    You can reference the options of a select object in your code by using the options property. The options property is an array that contains an entry for each option in a select object: selectName.options[0] is the first, selectName.options[1] is the second, etc. Each option has the properties listed below.

    Properties

    The select object has the following properties:

  • length reflects the number of options in the select object
  • name reflects the NAME attribute
  • options reflects the <OPTION> tags
  • selectedIndex reflects the index of the selected option

    The options property has the following properties:

  • defaultSelected reflects the SELECTED attribute
  • index reflects the index of an option
  • length reflects the number of options in the select object
  • name reflects the NAME attribute
  • options reflects the full HTML statement for the select object
  • selected lets you programatically select an option
  • selectedIndex reflects the index of the selected option
  • text reflects the textToDisplay that follows an <OPTION> tag
  • value reflects the VALUE attribute

    Methods

    None.

    Event handlers

  • onBlur
  • onChange
  • onFocus

    Examples

    The following example displays a selection list and a scrolling list.

    Choose the music type for your free CD: <SELECT NAME="music_type_single"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT> <P>Choose the music types for your free CDs: <BR><SELECT NAME="music_type_multi" MULTIPLE> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>

    The following example displays two selection lists that let the user choose a month and day. These selection lists are initialized to the current date. The user can change the month and day by using the selection lists or by choosing preset dates from radio buttons. Text fields on the form display the values of the select object's properties and indicate the date chosen and whether it is Cinco de Mayo.

    <HTML> <HEAD> <TITLE>Select object example</TITLE> </HEAD> <BODY> <SCRIPT> var today = new Date() //--------------- function updatePropertyDisplay(monthObj,dayObj) { // Get date strings var monthInteger, dayInteger, monthString, dayString monthInteger=monthObj.selectedIndex dayInteger=dayObj.selectedIndex monthString=monthObj.options[monthInteger].text dayString=dayObj.options[dayInteger].text // Display property values document.selectForm.textFullDate.value=monthString + " " + dayString document.selectForm.textMonthLength.value=monthObj.length document.selectForm.textDayLength.value=dayObj.length document.selectForm.textMonthName.value=monthObj.name document.selectForm.textDayName.value=dayObj.name document.selectForm.textMonthIndex.value=monthObj.selectedIndex document.selectForm.textDayIndex.value=dayObj.selectedIndex // Is it Cinco de Mayo? if (monthObj.options[4].selected && dayObj.options[4].selected) { document.selectForm.textCinco.value="Yes!" } else { document.selectForm.textCinco.value="No" } } </SCRIPT> <!---------------> <FORM NAME="selectForm"> <P><B>Choose a month and day:</B> Month: <SELECT NAME="monthSelection" onChange="updatePropertyDisplay(this,document.selectForm.daySelection)"> <OPTION> January <OPTION> February <OPTION> March <OPTION> April <OPTION> May <OPTION> June <OPTION> July <OPTION> August <OPTION> September <OPTION> October <OPTION> November <OPTION> December </SELECT> Day: <SELECT NAME="daySelection" onChange="updatePropertyDisplay(document.selectForm.monthSelection,this)"> <OPTION> 1 <OPTION> 2 <OPTION> 3 <OPTION> 4 <OPTION> 5 <OPTION> 6 <OPTION> 7 <OPTION> 8 <OPTION> 9 <OPTION> 10 <OPTION> 11 <OPTION> 12 <OPTION> 13 <OPTION> 14 <OPTION> 15 <OPTION> 16 <OPTION> 17 <OPTION> 18 <OPTION> 19 <OPTION> 20 <OPTION> 21 <OPTION> 22 <OPTION> 23 <OPTION> 24 <OPTION> 25 <OPTION> 26 <OPTION> 27 <OPTION> 28 <OPTION> 29 <OPTION> 30 <OPTION> 31 </SELECT> <P><B>Set the date to: </B> <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=0; daySelection.selectedIndex=0; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> New Year's Day <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=4; daySelection.selectedIndex=4; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> Cinco de Mayo <INPUT TYPE="radio" NAME="dateChoice" onClick=" monthSelection.selectedIndex=5; daySelection.selectedIndex=20; updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection)"> Summer Solstice <P><B>Property values:</B> <BR>Date chosen: <INPUT TYPE="text" NAME="textFullDate" VALUE="" SIZE=20"> <BR>monthSelection.length<INPUT TYPE="text" NAME="textMonthLength" VALUE="" SIZE=20"> <BR>daySelection.length<INPUT TYPE="text" NAME="textDayLength" VALUE="" SIZE=20"> <BR>monthSelection.name<INPUT TYPE="text" NAME="textMonthName" VALUE="" SIZE=20"> <BR>daySelection.name<INPUT TYPE="text" NAME="textDayName" VALUE="" SIZE=20"> <BR>monthSelection.selectedIndex<INPUT TYPE="text" NAME="textMonthIndex" VALUE="" SIZE=20"> <BR>daySelection.selectedIndex<INPUT TYPE="text" NAME="textDayIndex" VALUE="" SIZE=20"> <BR>Is it Cinco de Mayo? <INPUT TYPE="text" NAME="textCinco" VALUE="" SIZE=20"> <SCRIPT> document.selectForm.monthSelection.selectedIndex=today.getMonth() document.selectForm.daySelection.selectedIndex=today.getDate()-1 updatePropertyDisplay(document.selectForm.monthSelection,document.selectForm.daySelection) </SCRIPT> </FORM> </BODY> </HTML>

    See also

  • form and radio objects
  • options property

    string object (common)

    A series of characters.

    Syntax

    To use a string object:

    1. stringName.propertyName
    2. stringName.methodName(parameters)
    
    stringName is the name of a string variable.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A string can be represented as a literal enclosed by single or double quotes; for example, "Netscape" or 'Netscape'.

    Properties

  • length reflects the length of the string

    Methods

  • anchor
  • big
  • blink
  • bold
  • charAt
  • fixed
  • fontcolor
  • fontsize
  • indexOf
  • italics
  • lastIndexOf
  • link
  • small
  • strike
  • sub
  • substring
  • sup
  • toLowerCase
  • toUpperCase

    Event handlers

    None. Built-in objects do not have event handlers.

    Examples

    The following statement creates a string variable.

    var last_name = "Schaefer" The following statements evaluate to 8, "SCHAEFER", and "schaefer": last_name.length last_name.toUpperCase() last_name.toLowerCase()

    See also

  • text and textarea objects

    submit object (client)

    A submit button on an HTML form. A submit button causes a form to be submitted.

    Syntax

    To define a submit button, use standard HTML syntax with the addition of the onClick event handler:

    <INPUT
       TYPE="submit"
       NAME="submitName"
       VALUE="buttonText"
       [onClick="handlerText"]>
    
    NAME="submitName" specifies the name of the submit object. You can access this value using the name property.
    VALUE="buttonText" specifies the label to display on the button face. You can access this value using the value property.

    To use a submit object's properties and methods:

    1. submitName.propertyName
    2. submitName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    submitName is the value of the NAME attribute of a submit object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a submit object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A submit object is a form element and must be defined within a <FORM>...</FORM> tag.

    Clicking a submit button submits a form to the URL specified by the form's action property. This action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified.

    Properties

  • name reflects the NAME attribute
  • value reflects the VALUE attribute

    Methods

  • click

    Event handlers

  • onClick

    Examples

    The following example creates a submit object called submit_button. The text "Done" is displayed on the face of the button.

    <INPUT TYPE="submit" NAME="submit_button" VALUE="Done">

    See also

  • button, form, and reset objects
  • submit method

    text object (client)

    A text input field on an HTML form. A text field lets the user enter a word, phrase, or series of numbers.

    Syntax

    To define a text object, use standard HTML syntax with the addition of the onBlur, on Change, onFocus, and onSelect event handlers:

    <INPUT
       TYPE="text"
       NAME="textName"
       VALUE="textValue"
       SIZE=integer
       [onBlur="handlerText"]
       [onChange="handlerText"]
       [onFocus="handlerText"]
       [onSelect="handlerText"]>
    
    NAME="textName" specifies the name of the text object. You can access this value using the name property.
    VALUE="textValue" specifies the initial value of the text object. You can access this value using the defaultValue property.
    SIZE=integer specifies the number of characters the text object can accommodate without scrolling.

    To use a text object's properties and methods:

    1. textName.propertyName
    2. textName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    textName is the value of the NAME attribute of a text object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a text object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A text object is a form element and must be defined within a <FORM>...</FORM> tag.

    text objects can be updated (redrawn) dynamically by setting the value property (this.value).

    Properties

  • defaultValue reflects the VALUE attribute
  • name reflects the NAME attribute
  • value reflects the current value of the text object's field

    Methods

  • focus
  • blur
  • select

    Event handlers

  • onBlur
  • onChange
  • onFocus
  • onSelect

    Examples

    <B>Last name:</B> <INPUT TYPE="text" NAME="last_name" VALUE="" SIZE=25>

    See also

  • form, password, string, and textarea objects

    textarea object (client)

    A multiline input field on an HTML form. A textarea field lets the user enter words, phrases, or numbers.

    Syntax

    To define a text area, use standard HTML syntax with the addition of the onBlur, onChange, onFocus, and onSelect event handlers:

    <TEXTAREA
       NAME="textareaName"
       ROWS="integer"
       COLS="integer"
       [onBlur="handlerText"]
       [onChange="handlerText"]
       [onFocus="handlerText"]
       [onSelect="handlerText"]>
       textToDisplay
    </TEXTAREA>
    
    NAME="textareaName" specifies the name of the textarea object. You can access this value using the name property.
    ROWS="integer" and COLS="integer" define the physical size of the displayed input field in numbers of characters.
    textToDisplay specifies the initial value of the textarea object. A textarea allows only ASCII text, and new lines are respected. You can access this value using the defaultValue property.

    To use a textarea object's properties and methods:

    1. textareaName.propertyName
    2. textareaName.methodName(parameters)
    3. formName.elements[index].propertyName
    4. formName.elements[index].methodName(parameters)
    
    textareaName is the value of the NAME attribute of a textarea object.
    formName is either the value of the NAME attribute of a form object or an element in the forms array.
    index is an integer representing a textarea object on a form.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    Description

    A textarea object is a form element and must be defined within a <FORM>...</FORM> tag.

    textarea objects can be updated (redrawn) dynamically by setting the value property (this.value).

    Properties

  • defaultValue reflects the VALUE attribute
  • name reflects the NAME attribute
  • value reflects the current value of the textarea object

    Methods

  • focus
  • blur
  • select

    Event handlers

  • onBlur
  • onChange
  • onFocus
  • onSelect

    Examples

    <B>Description:</B> <BR><TEXTAREA NAME="item_description" ROWS=6 COLS=55> Our storage ottoman provides an attractive way to store lots of CDs and videos--and it's versatile enough to store other things as well. It can hold up to 72 CDs under the lid and 20 videos in the drawer below. </TEXTAREA>

    See also

  • form, password, string, and text objects

    window object (client)

    The top-level object for each document, location, and history object group.

    Syntax

    To define a window, use the open method:

    windowVar = window.open("URL", "windowName", ["windowFeatures"])
    
    windowVar is the name of a new window. Use this variable when referring to a window's properties, methods, and containership.
    windowName is the window name to use in the TARGET attribute of a <FORM> or <A> tag. For details on defining a window, see the open method.

    To use a window object's properties and methods:

     1. window.propertyName
     2. window.methodName
     3. self.propertyName
     4. self.methodName
     5. top.propertyName
     6. top.methodName
     7. parent.propertyName
     8. parent.methodName
     9. windowVar.propertyName
    10. windowVar.methodName
    11. propertyName
    12. methodName
    
    windowVar is a variable referring to a window object. See the preceding syntax for defining a window.
    propertyName is one of the properties listed below.
    methodName is one of the methods listed below.

    To define an onLoad or onUnload event handler for a window object, use the <BODY> or <FRAMESET> tags:

    <BODY
       ...
       [onLoad="handlerText"]
       [onUnload="handlerText"]>
    </BODY>
    
    <FRAMESET
       ROWS="rowHeightList"
       COLS="columnWidthList"
       [onLoad="handlerText"]
       [onUnload="handlerText"]>
       [<FRAME SRC="locationOrURL" NAME="frameName">]
    </FRAMESET>
    

    For information on the <BODY> and <FRAMESET> tags, see the document and frame objects.

    Description

    The window object is the top-level object in the JavaScript client hierarchy. Frame objects are also windows.

    The self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either window.close() or self.close(). You can use these properties to make your code more readable, or to disambiguate the property reference self.status from a form called status. See the properties and methods listed below for more examples.

    The top and parent properties are also synonyms that can be used in place of the window name. Top refers to the top-most Navigator window, and parent refers to a window containing a frameset. See the top and parent properties.

    Because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. For example, status="Jump to a new location" is a valid property assignment, and close() is a valid method call.

    You can reference a window's frame objects in your code by using the frames property. The frames property is an array that contains an entry for each frame in a window containing a <FRAMESET> tag.

    Windows lack event handlers until some HTML is loaded into them containing a <BODY> or <FRAMESET> tag.

    Properties

  • defaultStatus reflects the default message displayed in the window's status bar
  • frames is a reflection of all the frames in a window
  • length reflects the number of frames in a parent window
  • name reflects the windowName argument
  • parent is a synonym for the windowName argument and refers to a window containing a frameset
  • self is a synonym for the windowName argument and refers to the current window
  • status specifies a priority or transient message in the window's status bar
  • top is a synonym for the windowName argument and refers to the top-most Navigator window
  • window is a synonym for the windowName argument and refers to the current window

    Methods

  • alert
  • close
  • confirm
  • open
  • prompt
  • setTimeout
  • clearTimeout

    Event handlers

  • onLoad
  • onUnload

    Examples

    In the following example, the document in the top window opens a second window, window2, and defines pushbuttons that open a message window, write to the message window, close the message window, and close window2. The onLoad and onUnload event handlers of the document loaded into window2 display alerts when the window opens and closes.

    WIN1.HTML, which defines the frames for the first window, contains the following code:

    <HTML> <HEAD> <TITLE>Window object example: Window 1</TITLE> </HEAD> <BODY BGCOLOR="antiquewhite"> <SCRIPT> window2=open("win2.html","secondWindow","scrollbars=yes,width=250, height=400") document.writeln("<B>The first window has no name: " + window.name + "</B>") document.writeln("<BR><B>The second window is named: " + window2.name + "</B>") </SCRIPT> <FORM NAME="form1"> <P><INPUT TYPE="button" VALUE="Open a message window" onClick="window3=window.open('','messageWindow','scrollbars=yes,width=175, height=300')"> <P><INPUT TYPE="button" VALUE="Write to the message window" onClick="window3.document.writeln('Hey there');window3.document.close()"> <P><INPUT TYPE="button" VALUE="Close the message window" onClick="window3.close()"> <P><INPUT TYPE="button" VALUE="Close window2" onClick="window2.close()"> </FORM> </BODY> </HTML>

    WIN2.HTML, which defines the content for window2, contains the following code:

    <HTML> <HEAD> <TITLE>Window object example: Window 2</TITLE> </HEAD> <BODY BGCOLOR="oldlace" onLoad="alert('Message from ' + window.name + ': Hello, World.')" onUnload="alert('Message from ' + window.name + ': I\'m closing')"> <B>Some numbers</B> <LI>one <LI>two <LI>three <LI>four <LI>five <LI>six <LI>seven <LI>eight <LI>nine </BODY> </HTML>

    See also the example for the frame object.

    See also

  • document and frame objects
  • frames property