Javascript-Referência JavaScript - Letras T a Z
[arquivo anterior (letras S a S)]

taint

function. adds tainting to a data element or script.

syntax

taint(dataelementname)

parameters

dataelementname is the property, variable, function, or object to taint. if omitted, taint is added to the script itself.

implemented in

navigator 3.0

description

tainting prevents other scripts from passing information that should be secure and private, such as directory structures or user session history. javascript cannot pass tainted values on to any server without the end user's permission.

use taint to mark data that otherwise is not tainted.

in some cases, control flow rather than data flow carries tainted information. in these cases, taint is added to the script's window. you can add taint to the script's window by calling taint with no arguments. see "tainting that results from conditional statements".

taint does not modify its argument; instead, it returns a marked copy of the value, or, for objects, an unmarked reference to the value.

examples

the following statement adds taint to a property so that a script cannot send it to another server without the end user's permission:

taintedstatus=taint(window.defaultstatus)
// taintedstatus now cannot be sent in a url or form post without
// the end user's permission

see also

domain property; taintenabled method; untaint function; "using data tainting for security"


taintenabled

method. specifies whether data tainting is enabled.

syntax

navigator.taintenabled()

method of

navigator

implemented in

navigator 3.0

description

tainting prevents other scripts from passing information that should be secure and private, such as directory structures or user session history. javascript cannot pass tainted values on to any server without the end user's permission.

use taintenabled to determine if data tainting is enabled. taintenabled returns true if data tainting is enabled, false otherwise. the user enables or disables data tainting by using the environment variable ns_enable_taint.

examples

the following code executes function1 if data tainting is enabled; otherwise it executes function2.

if (navigator.taintenabled()) {
   function1()
}
else function2()

see also

domain property; taint, untaint functions; "using data tainting for security"


tan

method. returns the tangent of a number.

syntax

math.tan(number)

parameters

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

method of

math

implemented in

navigator 2.0

description

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

examples

the following function returns the tangent of the variable x:

function gettan(x) {
   return math.tan(x)
}
if you pass gettan the value math.pi/4, it returns 0.9999999999999999.

see also

acos, asin, atan, atan2, 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
3. areaname.target

parameters

formname is either the name of a form or an element in the forms0 array.

index is an integer representing a link object or the name of a link object as specified by the name attribute.

areaname is the value of the name attribute of an area object.

property of

area object (see link object), form object, link object

implemented in

tainted?

no

description

the target property initially reflects the target attribute of the <a>, <area>, and <form> tags; however, setting target overrides these attributes.

you can set target using a string, if the string represents a window name. the target property cannot be assigned the value of a javascript expression or variable.

you can set the target property at any time.

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; form object


text object

object. a text input field on an html form. the user can enter a word, phrase, or series of numbers in a text field.

html syntax

to define a text object, use standard html syntax with the addition of javascript event handlers:

<input
   type="text"
   name="textname"
   value="textvalue"
   size=integer
   [onblur="handlertext"]
   [onchange="handlertext"]
   [onfocus="handlertext"]
   [onselect="handlertext"]>

html attributes

name="textname" specifies the name of the text object. you can access this value using the name property, and you can use this name when indexing the elements array.

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.

syntax

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)

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 or the name of a text object as specified by the name attribute.

propertyname is one of the properties listed below.

methodname is one of the methods listed below.

property of

form object

implemented in

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).

if a form contains only one element, a text object, then when the user enters a value and presses return, the form submits. (this is a standard html feature.)

properties

the text object has the following properties:

property description
defaultvalue
reflects the value attribute
form property
specifies the form containing the text object
name
reflects the name attribute
type
reflects the type attribute
value
reflects the current value of the text object's field

methods

the text object has the following methods:

  • blur
  • eval
  • focus
  • select method
  • tostring
  • valueof
  • event handlers

    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 uppercase.

    <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

    fileupload object, form object, password object, string object, textarea object


    text property

    property. a string specifying the text that follows an <option> tag in a select object.

    syntax

    1. selectname.options[index].text
    2. optionname.text

    parameters

    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.

    optionname is the name of a select object option created using the option() constructor.

    property of

    option object (see select object), options array (see select object)

    implemented in

    tainted?

    yes

    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 and the text displayed by the option in the select object changes.

    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. the user can use a textarea field to enter words, phrases, or numbers.

    html syntax

    to define a text area, use standard html syntax with the addition of javascript event handlers:

    <textarea
       name="textareaname"
       rows="integer"
       cols="integer"
       [onblur="handlertext"]
       [onchange="handlertext"]
       [onfocus="handlertext"]
       [onselect="handlertext"]>
       texttodisplay
    </textarea>

    html attributes

    name="textareaname" specifies the name of the textarea object. you can access this value using the name property, and you can use this name when indexing the elements array.

    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.

    syntax

    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)

    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 or the name of a textarea object as specified by the name attribute.

    propertyname is one of the properties listed below.

    methodname is one of the methods listed below.

    property of

    form object

    implemented in

    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. although this character varies from platform to platform (unix is \n, windows is \r, and macintosh is \n), javascript checks for all newline characters before setting a string-valued property and translates them as needed for the user's platform. you could also enter a newline character programmatically--one way is to test the appversion property to determine the current platform, then set the newline character accordingly. see the appversion property for an example.

    properties

    the textarea object has the following properties:

    property description
    defaultvalue
    reflects the value attribute
    form property
    specifies the form containing the textarea object
    name
    reflects the name attribute
    type
    specifies that the object is a textarea object
    value
    reflects the current value of the textarea object

    methods

    the textarea object has the following methods:

  • blur
  • eval
  • focus
  • select method
  • tostring
  • valueof
  • event handlers

    examples

    example 1. the following example creates a textarea object that is six 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>
    example 2. the following example creates a string variable containing newline two characters for different platforms. when the user clicks the button, the textarea object is populated with the value from the string variable. the result is three lines of text in the textarea object.

    <script>
    mystring="this is line one.\nthis is line two.\rthis is line three."
    </script>
    <form name="form1">
    <input type="button" value="populate the textarea"
    onclick="document.form1.textarea1.value=mystring">
       <p>
    <textarea name="textarea1" rows=6 cols=55></textarea>
    see also the examples for the onblur, onchange, onfocus, and onselect event handlers.

    see also

    form object, password object, string object, text object


    title

    property. a string representing the title of a document.

    syntax

    document.title

    property of

    document

    implemented in

    navigator 2.0

    tainted?

    yes

    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://home.netscape.com")
    var doctitle = newwindow.document.title

    togmtstring

    method. converts a date to a string, using the internet gmt conventions.

    syntax

    dateobjectname.togmtstring()

    parameters

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

    method of

    date

    implemented in

    navigator 2.0

    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()

    parameters

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

    method of

    date

    implemented in

    navigator 2.0

    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 gives 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 lowercase.

    syntax

    stringname.tolowercase()

    parameters

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

    method of

    string

    implemented in

    navigator 2.0

    description

    the tolowercase method returns the value of stringname converted to lowercase. tolowercase does not affect the value of stringname itself.

    examples

    the following example displays the lowercase string "alphabet":

    var uppertext="alphabet"
    document.write(uppertext.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]

    parameters

    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 object

    implemented in

    navigator 2.0

    tainted?

    no

    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 three:

    <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"

    tostring

    method. returns a string representing the specified object.

    syntax

    objectname.tostring()
    numberobjectname.tostring([radix])

    parameters

    objectname is the object to convert to a string.

    numberobjectname is the number object to convert to a string.

    radix is an integer between 2 and 16 specifying the base to use for representing numeric values.

    method of

    tostring is a method of all objects.

    implemented in

    navigator 2.0

    navigator 3.0: added radix

    tainted?

    yes, for history, location, link, and any form input element; no for all other objects

    description

    every object has a tostring method that is automatically called when it is to be represented as a text value or when an object is referenced in a string concatenation. for example, the following examples require thedog to be represented as a string:

    document.write(thedog)
    document.write("the dog is " + thedog)
    you can use tostring within your own code to convert an object into a string, and you can create your own function to be called in place of the default tostring method.

    built-in tostring methods

    every object type has a built-in tostring method, which javascript calls whenever it needs to convert an object to a string. if an object has no string value and no user-defined tostring method, tostring returns "[object type]", where type is the object type or the name of the constructor function that created the object. for example, if the following image object named "sealife" exists, sealife.tostring() returns [object image].

    <img name="sealife" src="images\seaotter.gif" align="left" vspace="10">

    user-defined tostring methods

    you can create a function to be called in place of the default tostring method. the tostring method takes no arguments and should return a string. the tostring method you create can be any value you want, but it will be most useful if it carries information about the object.

    suppose you have an object type dog and you want to create a tostring method for it. the following code defines the dog object type and creates thedog, an object of type dog:

    function dog(name,breed,color,sex) {
       this.name=name
       this.breed=breed
       this.color=color
       this.sex=sex
    }

    thedog = new dog("gabby","lab","chocolate","girl")
    the following code creates objecttostring, the function that will be used in place of the default tostring method. this function generates a string containing each property, of the form "property = value;".

    function objecttostring() {
       var ret = "object " + this.name + " is ["
       for (var prop in this)
          ret += " " + prop + " is " + this[prop] + ";"
       return ret + "]"
    }
    the following code assigns the user-defined function to the object's tostring method:

    dog.prototype.tostring = objecttostring
    with the preceding code in place, any time thedog is used in a string context, javascript automatically calls the objecttostring function, which returns the following string:

    object gabby is [ name is gabby; breed is lab; color is chocolate; sex is girl; tostring is function objecttostring() { var ret = "object " + this.name + " is ["; for (var prop in this) { ret += " " + prop + " is " + this[prop] + ";"; } return ret + "]"; } ;]

    an object's tostring method is usually invoked by javascript, but you can invoke it yourself as follows:

    alert(thedog.tostring())

    arrays and tostring

    for array objects, the built-in tostring method joins the array and returns one string containing each array element separated by commas. for example, the following code creates an array and uses tostring to convert the array to a string while writing output.

    var monthnames = new array("jan","feb","mar","apr")
    document.write("monthnames.tostring() is " + monthnames.tostring())
    the output is as follows:

    monthnames.tostring() is jan,feb,mar,apr

    boolean objects and tostring

    for boolean objects and values, the built-in tostring method returns "true" or "false" depending on the value of the boolean object. in the following code, flag.tostring returns "true".

    flag = new boolean(true)
    document.write("flag.tostring() is " + flag.tostring() + "<br>")

    functions and tostring

    for function objects, the built-in tostring method decompiles the function back into the javascript source that defines the function. this string includes the function keyword, the argument list, curly braces, and function body.

    for example, suppose you create the function dog shown in "user-defined tostring methods". any time dog is used in a string context, javascript automatically calls the tostring function, which returns the following string:

    function dog(name, breed, color, sex) { this.name = name; this.breed = breed; this.color = color; this.sex = sex; }

    numbers and tostring

    you can use tostring on numeric values, but not on numeric literals:

    // the next two lines are valid
    var howmany=10
    document.write("howmany.tostring() is " + howmany.tostring() + "<br>")
    // the next line causes an error
    document.write("45.tostring() is " + 45.tostring() + "<br>")

    examples

    example 1: the location object. the following example prints the string equivalent of the current location.

    document.write("location.tostring() is " + location.tostring() + "<br>")
    the output is as follows:

    file:///c|/temp/myprog.html
    example 2: object with no string value. suppose the following image object named "sealife" exists:

    <img name="sealife" src="images\seaotter.gif" align="left" vspace="10">
    because the image object itself has no string equivalent, sealife.tostring() will return the following:

    [object image]
    example 3: the radix parameter. the following example prints the string equivalents of the numbers 0 through 9 in decimal and binary.

    for (x = 0; x < 10; x++) {
       document.write("decimal: ", x.tostring(10), " binary: ",
          x.tostring(2), "<br>")
    }
    the preceding example produces the following output:

    decimal: 0 binary: 0
    decimal: 1 binary: 1
    decimal: 2 binary: 10
    decimal: 3 binary: 11
    decimal: 4 binary: 100
    decimal: 5 binary: 101
    decimal: 6 binary: 110
    decimal: 7 binary: 111
    decimal: 8 binary: 1000
    decimal: 9 binary: 1001

    see also

    prototype property; valueof method


    touppercase

    method. returns the calling string value converted to uppercase.

    syntax

    stringname.touppercase()

    parameters

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

    method of

    string

    implemented in

    navigator 2.0

    description

    the touppercase method returns the value of stringname converted to uppercase. touppercase does not affect the value of stringname itself.

    examples

    the following example displays the string "alphabet":

    var lowertext="alphabet"
    document.write(lowertext.touppercase())

    see also

    tolowercase method


    type

    property. for form elements created with the <input>, <select>, or <textarea> tags, a string specifying the type of form element. for mimetype objects, the a string specifying the name of the mime type.

    syntax

    1. objectname.type
    2. navigator.mimetypes[index].type

    parameters

    objectname is either the value of the name attribute of a form element object (button, checkbox, file upload, hidden, password, radio, reset, select, submit, text, or textarea) or an element in the elements array.

    index is either an integer representing a mime type supported by the client or a string containing the type of a mimetype object (from the type property).

    property of

    button object, checkbox object, fileupload object, hidden object, mimetype object, password object, radio object, reset object, select object, submit object, text object, textarea object

    implemented in

    navigator 3.0

    tainted?

    no

    description

    for mimetype objects, the type property is a unique string that distinguishes the mime type from all others; for example "video/mpeg" or "audio/x-wav".

    for form elements, the value of the type property is assigned as follows:

    html element value of type property
    input type="button"
    "button"
    input type="checkbox"
    "checkbox"
    input type="file"
    "file"
    input type="hidden"
    "hidden"
    input type="password"
    "password"
    input type="radio"
    "radio"
    input type="reset"
    "reset"
    input type="submit"
    "submit"
    input type="text"
    "text"
    select
    "select-one"
    select multiple
    "select-multiple"
    textarea
    "textarea"

    type is a read-only property.

    examples

    the following example writes the value of the type property for every element on a form.

    for (var i = 0; i < document.form1.elements.length; i++) {
       document.writeln("<br>type is " + document.form1.elements[i].type)
    }
    see also the examples for the mimetype object.

    see also

    for mimetype objects: description, enabledplugin, suffixes properties


    unescape

    function. returns the ascii string for the specified value.

    syntax

    unescape("string")

    parameters

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

    implemented in

    navigator 2.0

    description

    the string returned by the unescape function is a series of characters in the iso latin-1 character set. the unescape function is a top-level javascript function not associated with any object.

    examples

    the following example returns "&":

    unescape("%26")
    the following example returns "!#":

    unescape("%21%23")

    see also

    escape function


    untaint

    function. removes tainting from a data element or script.

    syntax

    untaint(dataelementname)

    parameters

    dataelementname is the property, variable, function, or object to remove tainting from. if omitted, taint is removed from the script itself.

    implemented in

    navigator 3.0

    description

    tainting prevents other scripts from passing information that should be secure and private, such as directory structures or user session history. javascript cannot pass tainted values on to any server without the end user's permission.

    use untaint to clear tainting that marks data that should not to be sent by other scripts to different servers.

    a script can untaint only data that originated in that script (that is, only data that has the script's taint code or has the identity (null) taint code). if you use untaint with a data element from another server's script (or any data that you cannot untaint), untaint returns the data without change or error.

    in some cases, control flow rather than data flow carries tainted information. in these cases, taint is added to the script's window. you can remove taint from the script's window by calling untaint with no arguments, if the window contains taint only from the current window. see "tainting that results from conditional statements".

    untaint does not modify its argument; instead, it returns an unmarked copy of the value, or, for objects, an unmarked reference to the value.

    examples

    the following statement removes taint from a property so that a script can send it to another server:

    untaintedstatus=untaint(window.defaultstatus)
    // untaintedstatus can now be sent in a url or form post by other
    // scripts

    see also

    domain property; taint function; "using data tainting for security"


    url

    property. a string specifying the complete url of the document.

    syntax

    document.url

    property of

    document

    implemented in

    navigator 2.0

    tainted?

    yes

    description

    url is a read-only property of document containing the full url of the document. url is a string-valued property that usually matches what window.location.href is set to when you load the document, but redirection may change location.href.

    examples

    the following example displays the url of the current document:

    document.write("the current url is " + document.url)

    see also

    href


    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

    implemented in

    navigator 2.0

    tainted?

    no

    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

    appcodename, appname, appversion, javaenabled 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])

    parameters

    year is a year after 1900.

    month is a month between zero and 11.

    date is a day of the month between one and 31.

    hrs is hours between zero and 23.

    min is minutes between zero and 59.

    sec is seconds between zero and 59.

    method of

    date

    implemented in

    navigator 2.0

    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
    4. fileuploadname.value
    5. optionname.value

    parameters

    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.

    fileuploadname is either the value of the name attribute of a fileupload object or an element in the elements array.

    optionname is the name of a select object option created using the option() constructor.

    property of

    implemented in

  • navigator 2.0
  • navigator 3.0: property of fileupload, option

    tainted?

    yes

    description

    the value property differs for every object.

    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:

    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 on-screen; it is used to reference the objects programmatically.

    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 on-screen 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.

    fileupload objects

    the value property is a string that reflects the current value of a fileupload object's field. use the value property to obtain the file name that the user typed into a fileupload object.

    value is a read-only property.

    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 programmatically 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 unless data tainting is enabled. see "using data tainting for security".

    select object options

    for select object options created using the option() constructor, the value property is a string that initially reflects the value attribute. this value is not displayed onscreen, but is returned to the server if the option is selected. the value of this property can change when a program modifies it.

    you can set the value property at any time.

    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 on-screen 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.

    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


    valueof

    method. returns the primitive value of the specified object.

    syntax

    objectname.valueof()

    parameters

    objectname is the object to converted to a value.

    method of

    valueof is a method of all objects.

    implemented in

    navigator 3.0

    description

    every object has a valueof method that is automatically called when it is to be represented as a primitive value. if an object has no primitive value, valueof returns the object itself.

    you can use valueof within your own code to convert an object into a primitive value, and you can create your own function to be called in place of the default valueof method.

    built-in valueof methods

    every object type has a built-in valueof method, which javascript calls whenever it needs to convert an object to a primitive value.

    you rarely need to invoke the valueof method yourself. javascript automatically invokes it when encountering an object where a primitive value is expected.

    the valueof method is most useful for the following object types. most other objects have no primitive value.

    object type value returned by valueof
    number
    primitive numeric value associated with the object.
    boolean
    primitive boolean value associated with the object.
    string
    string associated with the object.
    function
    function reference associated with the object. for example, typeof funobj returns "object", but typeof funobj.valueof() returns "function".

    user-defined valueof methods

    you can create a function to be called in place of the default valueof method. the valueof method takes no arguments.

    suppose you have an object type mynumbertype and you want to create a valueof method for it. the following code assigns a user-defined function to the object's valueof method:

    mynumbertype.prototype.valueof = new function(functiontext)
    with the preceding code in place, any time an object of type mynumbertype is used in a context where it is to be represented as a primitive value, javascript automatically calls the function defined in the preceding code.

    an object's valueof method is usually invoked by javascript, but you can invoke it yourself as follows:

    mynumber.valueof()

    tostring vs. valueof for string objects

    objects in string contexts convert via the tostring method, which is different from string objects converting to string primitives via valueof. all string objects have a string conversion, if only "[object type]". but many objects do not convert to number, boolean, or function. for information on tostring, see tostring.

    see also

    parseint function, tostring method; "typeof"


    vlinkcolor

    property. a string specifying the color of visited links.

    syntax

    document.vlinkcolor

    property of

    document

    implemented in

    navigator 2.0

    tainted?

    no

    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, linkcolor properties


    vspace

    property. a string specifying a margin in pixels between the top and bottom edges of an image and the surrounding text.

    syntax

    imagename.vspace

    parameters

    imagename is either the name of an image object or an element in the images array.

    property of

    image

    implemented in

    navigator 3.0

    tainted?

    no

    description

    the vspace property reflects the vspace attribute of the <img> tag. for images created with the image() constructor, the value of the vspace property is 0.

    vspace is a read-only property.

    examples

    see the examples for the height property.

    see also

    border, height, hspace, width properties


    width

    property. a string specifying the width of an image in pixels.

    syntax

    imagename.width

    parameters

    imagename is either the name of an image object or an element in the images array.

    property of

    image

    implemented in

    navigator 3.0

    tainted?

    no

    description

    the width property reflects the width attribute of the <img> tag. for images created with the image() constructor, the value of the width property is the actual, not the displayed, width of the image.

    width is a read-only property.

    examples

    see the examples for the height property.

    see also

    border, height, hspace, vspace properties


    window object

    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"])
    for details on defining a window, see the open (window object) 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)
    to define an event handler for a window object, use the <body> or <frameset> tags:

    <body
       ...
       [onblur="handlertext"]
       [onfocus="handlertext"]
       [onload="handlertext"]
       [onunload="handlertext"]>
    </body>

    <frameset
       rows="rowheightlist"
       cols="columnwidthlist"
       [onblur="handlertext"]
       [onfocus="handlertext"]
       [onload="handlertext"]
       [onunload="handlertext"]>
       [<frame src="url" name="framename">]
    </frameset>
    note
    on some platforms, placing an onblur or onfocus event handler in a <frameset> tag has no effect. please see the release notes (after starting netscape, choose release notes from the help menu).
    for information on the <body> and <frameset> tags, see the document and frame objects.

    to define an onerror event handler for a window object:

    window.onerror=errorhandler
    for information on specifying the onerror event handler, see onerror event handler.

    parameters

    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.

    propertyname is one of the properties listed below.

    methodname is one of the methods listed below.

    errorhandler is the keyword null, the name of an error-handling function, or a variable or property that contains null or a valid function reference.

    property of

    none

    implemented in

    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().

    when you reference the location object within an event handler, you must specify window.location instead of simply using location. due to the scoping of static objects in javascript, a call to location without specifying an object name is equivalent to document.location, which is a synonym for document.url.

    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

    the window object has the following properties:

    property description
    closed
    specifies whether a window has been closed
    defaultstatus
    reflects the default message displayed in the window's status bar
    frames
    an array reflecting all the frames in a window
    length
    reflects the number of frames in a parent window
    name
    reflects the windowname argument
    opener
    specifies the window name of the calling document when a window is opened using the open method
    parent
    a synonym for the windowname argument and refers to a window containing a frameset
    self
    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
    a synonym for the windowname argument and refers to the top-most navigator window
    window property
    a synonym for the windowname argument and refers to the current window

    the following objects are also properties of the window object:

    methods

    the window object has the following methods:

  • alert
  • blur
  • cleartimeout
  • close (window object)
  • confirm
  • eval
  • focus
  • open (window object)
  • prompt
  • scroll
  • settimeout
  • tostring
  • valueof
  • event handlers

    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>
    <ul><li>one
    <li>two
    <li>three
    <li>four</ul>
    </body>
    </html>
    see also the example for the frame object.

    see also

    document, frame objects


    window property

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

    syntax

    1. window.propertyname
    2. window.methodname

    parameters

    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 object, window object

    implemented in

    navigator 2.0

    tainted?

    no

    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])

    parameters

    expression1 through expressionn are any javascript expressions or the properties of existing objects.

    method of

    document

    implemented in

    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.

    you can use the write method to generate html and javascript code. however, the html parser reads the generated code as it is being written, so you might have to escape some characters. for example, the following write method generates a comment and writes it to window2:

    window2=window.open('','window2')
    begincomment="\<!--"
    endcomment="--\>"
    window2.document.write(begincomment)
    window2.document.write(" this some text inside a comment. ")
    window2.document.write(endcomment)

    printing, saving, and viewing generated html

    in navigator 3.0, users can print and save generated html using the commands on the file menu.

    to view html code that was generated with javascript write and writeln methods, the user must specify the view-source: protocol. if the user chooses document source or frame source from the view menu, the content displayed is that of the wysiwyg: url. the following example shows a view-source: url:

    view-source:wysiwyg://0/file:/c|/temp/genhtml.html
    for information on specifying the view-source: protocol in the location object, see the location object.

    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 (document object), open (document object), 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])

    parameters

    expression1 through expressionn are any javascript expressions or the properties of existing objects.

    method of

    document

    implemented in

    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 (document object), open (document object), write methods