tan method

Returns the tangent of a number.

Syntax

Math.tan(number)

number is a numeric expression representing the size of an angle in radians, or a property of an existing object.

Method of

Math

Description

The tan method returns a numeric value which represents the tangent of the angle.

Examples

//Displays the value 0.9999999999999999
document.write("The tangent of pi/4 radians is " +
   Math.tan(Math.PI/4))

//Displays the value 0
document.write("<P>The tangent of 0 radians is " +
   Math.tan(0))

See also

  • acos, asin, atan, cos, sin methods

    target property

    For form, a string specifying the name of the window that responses go to after a form has been submitted. For link, a string specifying the name of the window that displays the content of a clicked hypertext link.

    Syntax

    1. formName.target
    2. links[index].target
    

    formName is either the name of a form or an element in the forms array.
    index is an integer representing a link object.

    Property of

    form, link

    Description

    The target property initially reflects the TARGET attribute of the <FORM> and <A> tags; however, setting target overrides these attributes.

    The target property cannot be assigned the value of a JavaScript expression or variable.

    You can set the target property at any time.

    Certain values of the target property may require specific values for other form properties. See RFC 1867 for more information.

    Examples

    The following example specifies that responses to the musicInfo form are displayed in the "msgWindow" window:

    document.musicInfo.target="msgWindow"

    See also

    For form:

  • action, encoding, method properties

    text object

    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.

    Property of

  • form

    Description

    A text object on a form looks as follows:

    Last name:

    A text object is a form element and must be defined within a <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

    Example 1. The following example creates a text object that is 25 characters long. The text field appears immediately to the right of the words "Last name:". The text field is blank when the form loads.

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

    Example 2. The following example creates two text objects on a form. Each object has a default value. The city object has an onFocus event handler that selects all the text in the field when the user tabs to that field. The state object has an onChange event handler that forces the value to upper case.

    <FORM NAME="form1"> <BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Anchorage" SIZE="20" onFocus="this.select()"> <B>State: </B><INPUT TYPE="text" NAME="state" VALUE="AK" SIZE="2" onChange="this.value=this.value.toUpperCase()"> </FORM>

    See also the examples for the onBlur, onChange, onFocus, and onSelect event handlers.

    See also

  • form, password, string, and textarea objects

    text property

    A string specifying the text that follows an <OPTION> tag in a select object.

    Syntax

    selectName.options[index].text

    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing an option in a select object.

    Property of

    options array

    Description

    The text property initially reflects the text that follows an <OPTION> tag in a select object.

    You can set the text property at any time; however, the following effects result:

  • The value of the property changes.
  • The text displayed by the option in the select object does not change.

    Be careful if you change the text property. If you evaluate the property after you change it, the property contains the new value, not the value that is displayed onscreen.

    Examples

    In the following example, the getChoice() function returns the value of the text property for the selected option. The for loop evaluates every option in the musicType select object. The if statement finds the option that is selected.

    function getChoice() {
       for (var i = 0; i < document.musicForm.musicType.length; i++) {
          if (document.musicForm.musicType.options[i].selected == true) {
             return document.musicForm.musicType.options[i].text
          }
       }
       return null
    }
    
    The previous example assumes that the select object is similar to the following:
    <SELECT NAME="musicType">
       <OPTION SELECTED> R&B
       <OPTION> Jazz
       <OPTION> Blues
       <OPTION> New Age
    </SELECT>
    

    textarea object

    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"
       WRAP="off|virtual|physical"
       [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.

    The WRAP attribute controls word wrapping inside the TEXTAREA. The value "off" is default and lines are sent exactly as typed. The value "virtual" wraps in the display but are sent exactly as typed. The value "physical" wraps in the display and sends new-lines at the wrap points as if new-lines had been entered.

    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.

    Property of

  • form

    Description

    A textarea object on a form looks as follows:

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

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

    To begin a new line in a textarea object, you can use a newline character. This character varies from platform to platform: Unix is \n, Windows is \r\n, and Macintosh is \n. One way to enter a newline character programatically is to test the appVersion property to determine the current platform and set the newline character accordingly. See the appVersion property for an example.

    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

    The following example creates a textarea object that is 6 rows long and 55 columns wide. The textarea field appears immediately below the word "Description:". When the form loads, the textarea object contains several lines of data, including one blank line.

    <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 the examples for the onBlur, onChange, onFocus, and onSelect event handlers.

    See also

  • form, password, string, and text objects

    title property

    A string representing the title of a document.

    Syntax

    document.title

    Property of

    document

    Description

    The title property is a reflection of the value specified within the <TITLE> and </TITLE> tags. If a document does not have a title, the title property is null.

    title is a read-only property.

    Examples

    In the following example, the value of the title property is assigned to a variable called docTitle:

    var newWindow = window.open("http://www.netscape.com")
    var docTitle = newWindow.document.title
    

    toGMTString method

    Converts a date to a string, using the Internet GMT conventions.

    Syntax

    dateObjectName.toGMTString()

    dateObjectName is either the name of a date object or a property of an existing object.

    Method of

    Date

    Description

    The exact format of the value returned by toGMTString varies according to the platform.

    Examples

    In the following example, today is a date object:
    today.toGMTString()
    

    In this example, the toGMTString method converts the date to GMT (UTC) using the operating system's time zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.

    Mon, 18 Dec 1995 17:28:35 GMT

    See also

  • toLocaleString method

    toLocaleString method

    Converts a date to a string, using the current locale's conventions.

    Syntax

    dateObjectName.toLocaleString()

    dateObjectName is either the name of a date object or a property of an existing object.

    Method of

    Date

    Description

    If you are trying to pass a date using toLocaleString, be aware that different locales assemble the string in different ways. Using methods such as getHours, getMinutes, and getSeconds will give more portable results.

    Examples

    In the following example, today is a date object:
    today.toLocaleString()
    

    In this example, toLocaleString returns a string value that is similar to the following form. The exact format depends on the platform.

    12/18/95 17:28:35

    See also

  • toGMTString method

    toLowerCase method

    Returns the calling string value converted to lower case.

    Syntax

    stringName.toLowerCase()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    The toLowerCase method returns the value of stringName converted to lower case. toLowerCase does not affect the value of stringName itself.

    Examples

    The following examples both yield "alphabet".

    var upperText="ALPHABET"
    document.write(upperText.toLowerCase())
    
    "ALPHABET".toLowerCase()
    

    See also

  • toUpperCase method

    top property

    The top property is a synonym for the top-most Navigator window, which is a "document window" or "Web Browser window."

    Syntax

    1. top.propertyName
    2. top.methodName
    3. top.frameName
    4. top.frames[index]
    

    propertyName is defaultStatus, status, or length.
    methodName is any method associated with the window object.
    frameName and frames[index] are ways to refer to frames.

    Property of

    window

    Description

    The top property refers to the top-most window that contains frames or nested framesets. Use the top property to refer to this ancestor window.

    The top property is read-only. The value of the top property is

         <object objectReference>
    where objectReference is an internal reference.

    Examples

    The statement top.close() closes the top-most ancestor window.

    The statement top.length specifies the number of frames contained within the top-most ancestor window. When the top-most ancestor is defined as follows, top.length returns 3:

    <FRAMESET COLS="30%,40%,30%">
    <FRAME SRC=child1.htm NAME="childFrame1">
    <FRAME SRC=child2.htm NAME="childFrame2">
    <FRAME SRC=child3.htm NAME="childFrame3">
    </FRAMESET>
    

    The following example sets the background color of a frame called myFrame to red. myFrame is a child of the top-most ancestor window.

    top.myFrame.document.bgColor="red"
    

    toUpperCase method

    Returns the calling string value converted to upper case.

    Syntax

    stringName.toUpperCase()

    stringName is any string or a property of an existing object.

    Method of

    string

    Description

    The toUpperCase method returns the value of stringName converted to upper case. toUpperCase does not affect the value of stringName itself.

    Examples

    The following examples both yield "ALPHABET".

    var lowerText="alphabet"
    document.write(lowerText.toUpperCase())
    
    "alphabet".toUpperCase()
    

    See also

  • toLowerCase method

    unescape function

    Returns the ASCII string for the specified value.

    Syntax

    unescape("string")

    string is a string or a property of an existing object, containing characters in either of the following forms:

  • "%integer", where integer is a number between 0 and 255 (decimal)
  • "hex", where hex is a number between 0x0 and 0xFF (hexadecimal)

    Description

    The unescape function is not a method associated with any object, but is part of the language itself.

    The string returned by the unescape function is a series of characters in the ISO Latin-1 character set.

    Examples

    The following example returns "&"

    unescape("%26")
    

    The following example returns "!#"

    unescape("%21%23")
    

    See also

  • escape function

    userAgent property

    A string representing the value of the user-agent header sent in the HTTP protocol from client to server.

    Syntax

    navigator.userAgent

    Property of

    navigator

    Description

    Servers use the value sent in the user-agent header to identify the client.

    userAgent is a read-only property.

    Examples

    The following example displays userAgent information for the Navigator:

    document.write("The value of navigator.userAgent is " +
       navigator.userAgent)

    For Navigator 2.0, this displays the following:

    The value of navigator.userAgent is Mozilla/2.0 (Win16; I)

    See also

  • appName, appVersion, appCodeName properties

    UTC method

    Returns the number of milliseconds in a date object since January 1, 1970 00:00:00, Universal Coordinated Time (GMT).

    Syntax

    Date.UTC(year, month, day [, hrs] [, min] [, sec])

    year is a year after 1900.
    month is a month between 0-11.
    date is a day of the month between 1-31.
    hrs is hours between 0-23.
    min is minutes between 0-59.
    sec is seconds between 0-59.

    Method of

    Date

    Description

    UTC takes comma-delimited date parameters and returns the number of milliseconds since January 1, 1970 00:00:00, Universal Coordinated Time (GMT).

    Because UTC is a static method of Date, you always use it as Date.UTC(), rather than as a method of a date object you created.

    Examples

    The following statement creates a date object using GMT instead of local time:

    gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0))
    

    See also

  • parse method

    value property

    A string that is related to the VALUE attribute of its object.

    Syntax

    1. objectName.value
    2. radioName[index].value
    3. selectName.options.[index].value
    

    objectName is either the value of the NAME attribute of a hidden, password, text, textarea, button, reset, submit or checkbox object or an element in the elements array.
    radioName is the value of the NAME attribute of a radio object.
    selectName is either the value of the NAME attribute of a select object or an element in the elements array.
    index is an integer representing a radio button in a radio object or an option in a select object.

    Property of

  • button, checkbox, hidden, password, radio, reset, submit, text, textarea objects
  • options array

    Description

    The value property differs for every object.

    hidden, text, and textarea objects

    The value property is a string that initially reflects the VALUE attribute. This string is displayed in the text and textarea fields. The value of this property changes when a user or a program modifies the field.

    You can set the value property at any time. The display of the text and textarea objects updates immediately when you set the value property.

    password object

    The value property is a string that initially reflects the VALUE attribute. This string is represented by asterisks in the password object field. The value of this property changes when a user or a program modifies the field, but the value is always displayed as asterisks.

    If you programatically set the value property and then evaluate it, JavaScript returns the current value. If a user interactively modifies the value in the password field, you cannot evaluate it accurately for security reasons.

    button, reset, and submit objects

    When a VALUE attribute is specified in HTML, the value property is a string that reflects it. This string is displayed on the face of the button.

    When a VALUE attribute is not specified in HTML, the value property differs for each object:

  • For button, it is an empty string
  • For reset, it is the string "Reset"
  • For submit, it is the string "Submit Query"

    These strings are displayed on the faces of the buttons.

    value is a read-only property.

    Do not confuse the value property with the name property. The name property is not displayed onscreen; it is used to reference the objects programatically.

    options array

    The value property is a string that initially reflects the VALUE attribute. The value of this property can change when a program modifies it. The value property is not displayed onscreen, but is returned to the server if the option is selected.

    You can set the value property at any time.

    Do not confuse the value property with the selection state of the select object or the text that is displayed as an option. The selected and selectedIndex properties determine which options are selected, and the defaultSelected property determines the default selection state. The text that is displayed in each option is specified by its text property.

    checkbox and radio objects

    When a VALUE attribute is specified in HTML, the value property is a string that reflects it. When a VALUE attribute is not specified in HTML, the value property is a string that evaluates to "on". The value property is not displayed onscreen, but is returned to the server if the radio button or checkbox is selected.

    You can set the value property at any time.

    Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. The checked property determines the selection state of the object, and the defaultChecked property determines the default selection state. The text that is displayed is specified following the <INPUT TYPE="checkbox"> or the <INPUT TYPE="radio"> tag.

    Examples

    The following function evaluates the value property of a group of buttons and displays it in the msgWindow window:

    function valueGetter() {
       var msgWindow=window.open("")
       msgWindow.document.write("submitButton.value is " +
          document.valueTest.submitButton.value + "<BR>")
       msgWindow.document.write("resetButton.value is " +
          document.valueTest.resetButton.value + "<BR>")
       msgWindow.document.write("helpButton.value is " +
          document.valueTest.helpButton.value + "<BR>")
       msgWindow.document.close()
    }
    

    This example displays the following values:

    Query Submit
    Reset
    Help
    

    The previous example assumes the buttons have been defined as follows

    <INPUT TYPE="submit" NAME="submitButton">
    <INPUT TYPE="reset" NAME="resetButton">
    <INPUT TYPE="button" NAME="helpButton" VALUE="Help">
    

    The following function evaluates the value property of a group of radio buttons and displays it in the msgWindow window:

    function valueGetter() {
       var msgWindow=window.open("")
       for (var i = 0; i < document.valueTest.radioObj.length; i++) {
           msgWindow.document.write
              ("The value of radioObj[" + i + "] is " +
              document.valueTest.radioObj[i].value +"<BR>")
       }
       msgWindow.document.close()
    }
    

    This example displays the following values:

    on
    on
    on
    on
    

    The previous example assumes the buttons have been defined as follows

    <BR><INPUT TYPE="radio" NAME="radioObj">R&B
    <BR><INPUT TYPE="radio" NAME="radioObj" CHECKED>Soul
    <BR><INPUT TYPE="radio" NAME="radioObj">Rock and Roll
    <BR><INPUT TYPE="radio" NAME="radioObj">Blues
    

    See also

    For hidden, password, text, and textarea:

  • defaultValue property

    For button, reset, and submit:

  • name property

    For options array:

  • defaultSelected, selected, selectedIndex, text properties

    For checkbox and radio:

  • checked, defaultChecked properties

    vlinkColor property

    A string specifying the color of visited links.

    Syntax

    document.vlinkColor

    Property of

    document

    Description

    The vlinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values. This property is the JavaScript reflection of the VLINK attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the HTML source has been through layout.

    If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".

    Examples

    The following example sets the color of visited links to aqua using a string literal:

    document.vlinkColor="aqua"
    

    The following example sets the color of active links to aqua using a hexadecimal triplet:

    document.vlinkColor="00FFFF"
    

    See also

  • alinkColor, bgColor, fgColor, and linkColor properties

    window object

    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(parameters)
     3. self.propertyName
     4. self.methodName(parameters)
     5. top.propertyName
     6. top.methodName(parameters)
     7. parent.propertyName
     8. parent.methodName(parameters)
     9. windowVar.propertyName
    10. windowVar.methodName(parameters)
    11. propertyName
    12. methodName(parameters)
    
    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.

    Property of

  • None.

    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. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().

    You can reference a window's frame objects in your code by using the frames array. The frames array contains an entry for each frame in a window with 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 an array reflecting 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

    The following objects are also properties of the window object:

  • document
  • frame
  • location

    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

    window property

    The window property is a synonym for the current window or frame.

    Syntax

    1. window.propertyName
    2. window.methodName
    

    propertyName is the defaultStatus, status, length, or name property when the calling window refers to a window object.
    propertyName is the length or name property when the calling window refers to a frame object.
    methodName is any method associated with the window object.

    Property of

    frame, window

    Description

    The window property refers to the current window or frame.

    Although you can use the window property as a synonym for the current frame, your code is more readable if you use the self property. For example, window.name and self.name both specify the name of the current frame, but self.name is easier to understand.

    Use the window property to disambiguate a property of the window object from a form or form element of the same name. You can also use the window property to make your code more readable.

    The window property is read-only. The value of the window property is

         <object nameAttribute>
    where nameAttribute is the NAME attribute if window refers to a frame, or an internal reference if window refers to a window.

    Examples

    In the following example, window.status is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form called "status" within the current window.

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="window.status='Pick a random URL' ; return true"> Go!</A>

    See also

  • self property

    write method

    Writes one or more HTML expressions to a document in the specified window.

    Syntax

    document.write(expression1 [,expression2], ...[,expressionN])
    expression1 through expressionN are any JavaScript expressions or the properties of existing objects.

    Method of

    document

    Description

    The write method displays any number of expressions in a document window. You can specify any JavaScript expression with the write method, including numerics, strings, or logicals.

    The write method is the same as the writeln method, except the write method does not append a newline character to the end of the output.

    Use the write method within any <SCRIPT> tag or within an event handler. Event handlers execute after the original document closes, so the write method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.open() method in the event handler.

    Examples

    In the following example, the write method takes several arguments, including strings, a numeric, and a variable:
    var mystery = "world"
    // Displays Hello world testing 123
    msgWindow.document.write("Hello ", mystery, " testing ", 123)
    
    In the following example, the write method takes two arguments. The first argument is an assignment expression, and the second argument is a string literal.
    //Displays Hello world...
    msgWindow.document.write(mystr = "Hello "+ "world...")
    
    In the following example, the write method takes a single argument that is a conditional expression. If the value of the variable age is less than 18, the method displays "Minor". If the value of age is greater than or equal to 18, the method displays "Adult".
    msgWindow.document.write(status = (age >= 18) ? "Adult" : "Minor")
    

    See also

  • close, clear, open, writeln methods

    writeln method

    Writes one or more HTML expressions to a document in the specified window and follows them with a newline character.

    Syntax

    document.writeln(expression1 [,expression2], ...[,expressionN])
    expression1 through expressionN are any JavaScript expressions or the properties of existing objects.

    Method of

    document

    Description

    The writeln method displays any number of expressions in a document window. You can specify any JavaScript expression, including numerics, strings, or logicals.

    The writeln method is the same as the write method, except the writeln method appends a newline character to the end of the output. HTML ignores the newline character, except within certain tags such as <PRE>.

    Use the writeln method within any <SCRIPT> tag or within an event handler. Event handlers execute after the original document closes, so the writeln method will implicitly open a new document of mimeType text/html if you do not explicitly issue a document.open() method in the event handler.

    Examples

    All the examples used for the write method are also valid with the writeln method.

    See also

  • close, clear, open, write methods