Javascript-Referência JavaScript - Letras F a G
[Arquivo anterior (letras D a E)]      [Arquivo posterior (letras H a I)]

fgcolor

property. a string specifying the color of the document (foreground) text.

syntax

document.fgcolor

property of

document

implemented in

navigator 2.0

tainted?

no

description

the fgcolor 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 text 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."

you can override the value set in the fgcolor property in either of the following ways:

examples

the following example sets the color of the foreground text to aqua using a string literal:

document.fgcolor="aqua"
the following example sets the color of the foreground text to aqua using a hexadecimal triplet:

document.fgcolor="00ffff"

see also

alinkcolor, bgcolor, linkcolor, vlinkcolor properties; fontcolor method


filename

property. the name of a plug-in file on disk.

syntax

1. navigator.plugins[index].filename
2. navigator.plugins[pluginname].filename

parameters

index is either an integer representing a plug-in installed on the client or a string containing the name of a plugin object (from the name property).

property of

plugin

implemented in

navigator 3.0

tainted?

no

description

the filename property is the plug-in program's file name and is supplied by the plug-in itself. this name may vary from platform to platform.

filename is a read-only property.

examples

see the examples for the plugin object.

see also

description, length, name properties


fileupload

object. a file upload element on an html form. a file upload element lets the user supply a file as input.

html syntax

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

<input
   type="file"
   name="fileuploadname"
   [onblur="handlertext"]
   [onchange="handlertext"]
   [onfocus="handlertext"]
>

html attributes

name="fileuploadname" specifies the name of the fileupload object (this is not the name of the file to upload). you can access this value using the name property, and you can use this name when indexing the elements array.

syntax

to use a fileupload object's properties and methods:

fileuploadname.propertyname
fileuploadname
.methodname

parameters

fileuploadname is the value of the name attribute of a fileupload object.

propertyname is one of the properties listed below.

methodname is one of the properties listed below.

property of

form object

implemented in

navigator 3.0

description

a fileupload object on a form looks as follows:

      file containing your entry:
          

a fileupload object is a form element and must be defined within a <form> tag.

properties

the fileupload object has the following properties:

property description
form property
specifies the form containing the fileupload object
name
reflects the name attribute
type
reflects the type attribute
value
reflects the current value of the file upload element's field; this corresponds to the name of the file to upload. this is a read-only property for security purposes.

methods

the fileupload object has the following methods:

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

    examples

    the following example places a fileupload object on a form and provides two buttons that let the user display current values of the name and value properties.

    <form name="form1">
    file to send: <input type="file" name="myuploadobject">
    <p>get properties<br>
    <input type="button" value="name"
       onclick="alert('name: ' + document.form1.myuploadobject.name)">
    <input type="button" value="value"
       onclick="alert('value: ' + document.form1.myuploadobject.value)"><br>
    </form>

    see also

    text object


    fixed

    method. causes a string to be displayed in fixed-pitch font as if it were in a <tt> tag.

    syntax

    stringname.fixed()

    parameters

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

    method of

    string

    implemented in

    navigator 2.0

    description

    use the fixed method with the write or writeln methods to format and display a string in a document.

    examples

    the following example uses the fixed method to change the formatting of a string:

    var worldstring="hello, world"
    document.write(worldstring.fixed())
    the previous example produces the same output as the following html:

    <tt>hello, world</tt>

    floor

    method. returns the greatest integer less than or equal to a number.

    syntax

    math.floor(number)

    parameters

    number is any numeric expression or a property of an existing object.

    method of

    math

    implemented in

    navigator 2.0

    examples

    the following function returns the floor value of the variable x:

    function getfloor(x) {
       return math.floor(x)
    }
    if you pass getfloor the value 45.95, it returns 45; if you pass it the value -45.95, it returns -46.

    see also

    ceil method


    focus

    method. gives focus to the specified object.

    syntax

    1. fileuploadname.focus()
    2. passwordname.focus()
    3. selectname.focus()
    4. textname.focus()
    5. textareaname.focus()
    6. framereference.focus()
    7. windowreference.focus()

    parameters

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

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

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

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

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

    framereference is a valid way of referring to a frame, as described in the frame object.

    windowreference is a valid way of referring to a window, as described in the window object.

    method of

    button object, checkbox object, fileupload object, frame object, password object, radio object, reset object object, select object, submit object, text object, textarea object, window object

    implemented in

    description

    use the focus method to navigate to a specific form element, window, or frame, and give it focus. you can then either programmatically enter a value in the form element or let the user enter a value. giving focus to a window brings the window forward in most windowing systems.

    note
    on some platforms, the focus method gives focus to a frame but the focus is not visually apparent (for example, the frame's border is not darkened). please see the release notes (after starting netscape, choose release notes from the help menu).

    examples

    in the following example, the checkpassword function confirms that a user has entered a valid password. if the password is not valid, the focus method returns focus to the password object and the select method highlights it so the user can re-enter the password.

    function checkpassword(userpass) {
       if (badpassword) {
          alert("please enter your password again.")
          userpass.focus()
          userpass.select()
       }
    }
    this example assumes that the password object is defined as

    <input type="password" name="userpass">

    see also

    blur method, select method


    fontcolor

    method. causes a string to be displayed in the specified color as if it were in a <font color=color> tag.

    syntax

    stringname.fontcolor(color)

    parameters

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

    color is a string or a property of an existing object, expressing the color as a hexadecimal rgb triplet or as one of the string literals listed in "color values".

    method of

    string

    implemented in

    navigator 2.0

    description

    use the fontcolor method with the write or writeln methods to format and display a string in a document.

    if you express 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."

    the fontcolor method overrides a value set in the fgcolor property.

    examples

    the following example uses the fontcolor method to change the color of a string:

    var worldstring="hello, world"

    document.write(worldstring.fontcolor("maroon") +
       " is maroon in this line")
    document.write("<p>" + worldstring.fontcolor("salmon") +
       " is salmon in this line")
    document.write("<p>" + worldstring.fontcolor("red") +
       " is red in this line")

    document.write("<p>" + worldstring.fontcolor("8000") +
       " is maroon in hexadecimal in this line")
    document.write("<p>" + worldstring.fontcolor("fa8072") +
       " is salmon in hexadecimal in this line")
    document.write("<p>" + worldstring.fontcolor("ff00") +
       " is red in hexadecimal in this line")
    the previous example produces the same output as the following html:

    <font color="maroon">hello, world</font> is maroon in this line
    <p><font color="salmon">hello, world</font> is salmon in this line
    <p><font color="red">hello, world</font> is red in this line

    <font color="8000">hello, world</font> is maroon in hexadecimal in this line
    <p><font color="fa8072">hello, world</font> is salmon in hexadecimal in this line
    <p><font color="ff00">hello, world</font> is red in hexadecimal in this line

    fontsize

    method. causes a string to be displayed in the specified font size as if it were in a <fontsize=size> tag.

    syntax

    stringname.fontsize(size)

    parameters

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

    size is an integer between one and seven, a string representing a signed integer between one and seven, or a property of an existing object.

    method of

    string

    implemented in

    navigator 2.0

    description

    use the fontsize method with the write or writeln methods to format and display a string in a document.

    when you specify size as an integer, you set the size of stringname to one of the seven defined sizes. when you specify size as a string such as "-2," you adjust the font size of stringname relative to the size set in the <basefont> tag.

    examples

    the following example uses string methods to change the size of a string:

    var worldstring="hello, world"

    document.write(worldstring.small())
    document.write("<p>" + worldstring.big())
    document.write("<p>" + worldstring.fontsize(7))
    the previous example produces the same output as the following html:

    <small>hello, world</small>
    <p><big>hello, world</big>
    <p><fontsize=7>hello, world</fontsize>

    see also

    big, small methods


    form object

    object. lets users input text and make choices from form elements such as checkboxes, radio buttons, and selection lists. you can also use a form to post data to a server.

    html syntax

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

    <form
       name="formname"
       target="windowname"
       action="serverurl"
       method=get | post
       enctype="encodingtype"
       [onreset="handlertext"]
       [onsubmit="handlertext"]>
    </form>

    html attributes

    name="formname" specifies the name of the form object. you can access this value using the name property, and you can use this name when indexing the forms array.

    target="windowname" specifies the window that form responses go to. when you submit a form with a target attribute, server responses are displayed in the specified window instead of the window that contains the form. windowname can be an existing window; it can be a frame name specified in a <frameset> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a javascript expression (for example, it cannot be parent.framename or windowname.framename). you can access this value using the target property.

    action="serverurl" specifies the url of the server to which form field input information is sent. this attribute can specify a cgi or livewire application on the server; it can also be a mailto: url if the form is to be mailed. see the location object for a description of the url components. you can access this value using the action property.

    method=get | post specifies how information is sent to the server specified by action. get (the default) appends the input information to the url, which on most receiving systems becomes the value of the environment variable query_string. post sends the input information in a data body, which is available on stdin with the data length set in the environment variable content_length. if the method attribute has the value "post," then the enctype attribute typically has the value "application/x-www-form-urlencoded." you can access this value using the method property.

    enctype="encodingtype" specifies the mime encoding of the data sent: "application/x-www-form-urlencoded" (the default) or "multipart/form-data." use "multipart/form-data" if the form contains a file upload element (input type="file"). if the method attribute has the value "post," then the enctype attribute typically has the value "application/x-www-form-urlencoded." you can access this value using the encoding property.

    syntax

    to use a form object's properties and methods:

    1. formname.propertyname
    2. formname.methodname(parameters)
    3. forms[index].propertyname
    4. forms[index].methodname(parameters)

    parameters

    formname is the value of the name attribute of a form object.

    index is an integer representing a form object or the name of a form 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

    document

    implemented in

    description

    each form in a document is a distinct object.

    you can reference a form's elements in your code by using the element's name (from the name attribute) or the elements array. the elements array contains an entry for each element (such as a checkbox, radio, or text object) in a form.

    the forms array

    you can reference the forms in your code by using the forms array (you can also use the form name). this array contains an entry for each form object (<form> tag) in a document in source order. for example, if a document contains three forms, these forms are reflected as document.forms[0], document.forms[1], and document.forms[2].

    to use the forms array:

    1. document.forms[index]
    2. document.forms.length
    index is an integer representing a form in a document or the name of a form object as specified by the name attribute.

    to obtain the number of forms in a document, use the length property: document.forms.length.

    you can also refer to a form's elements by using the forms array. for example, you would refer to a text object named quantity in the second form as document.forms[1].quantity. you would refer to the value property of this text object as document.forms[1].quantity.value.

    elements in the forms array are read-only. for example, the statement document.forms[0]="music" has no effect.

    the value of each element in the forms array is <object nameattribute>, where nameattribute is the name attribute of the form.

    properties

    the form object has the following properties:

    property description
    action
    reflects the action attribute
    elements array
    an array reflecting all the elements in a form
    encoding
    reflects the enctype attribute
    length
    reflects the number of elements on a form
    name
    reflects the name attribute
    method
    reflects the method attribute
    target
    reflects the target attribute

    the following objects are also properties of the form object:

  • button
  • checkbox
  • fileupload
  • hidden
  • password
  • radio
  • reset object
  • select object
  • submit object
  • text object
  • textarea
  • the forms array has the following properties:

    property description
    length
    reflects the number of forms in the document

    methods

    the form object has the following methods:

  • eval method
  • reset method
  • submit method
  • tostring method
  • valueof method
  • event handlers

    examples

    example 1: named form. the following example creates a form called form1 that contains text fields for first name and last name. the form also contains two buttons that change the names to all uppercase or all lowercase. the function setcase shows how to refer to the form by its name.

    <html>
    <head>
    <title>form object example</title>
    </head>
    <script>
    function setcase (casespec){
    if (casespec == "upper") {
       document.form1.firstname.value=document.form1.firstname.value.touppercase()
       document.form1.lastname.value=document.form1.lastname.value.touppercase()}
       else {
       document.form1.firstname.value=document.form1.firstname.value.tolowercase()
       document.form1.lastname.value=document.form1.lastname.value.tolowercase()}
    }
    </script>
    <body>
    <form name="form1">
    <b>first name:</b>
    <input type="text" name="firstname" size=20>
    <br><b>last name:</b>
    <input type="text" name="lastname" size=20>
    <p><input type="button" value="names to uppercase" name="upperbutton"
       onclick="setcase('upper')">
    <input type="button" value="names to lowercase" name="lowerbutton"
       onclick="setcase('lower')">
    </form>
    </body>
    </html>
    example 2: forms array. the onload event handler in the following example displays the name of the first form in an alert dialog box.

    <body onload="alert('you are looking at the ' + document.forms[0] + ' form!')">
    if the form name is musictype, the alert displays the following message:

    you are looking at the <object musictype> form!
    example 3: onsubmit event handler. the following example shows an onsubmit event handler that determines whether to submit a form. the form contains one text object where the user enters three characters. the onsubmit event handler calls a function, checkdata, that returns true if the number of characters is three; otherwise, it returns false. notice that the form's onsubmit event handler, not the submit button's onclick event handler, calls the checkdata function. also, the onsubmit event handler contains a return statement that returns the value obtained with the function call.

    <html>
    <head>
    <title>form object/onsubmit event handler example</title>
    <title>form object example</title>
    </head>
    <script>
    var dataok=false
    function checkdata (){
    if (document.form1.threechar.value.length == 3) {
       return true}
       else {
          alert("enter exactly three characters. " + document.form1.threechar.value +
             " is not valid.")
          return false}
    }
    </script>
    <body>
    <form name="form1" onsubmit="return checkdata()">
    <b>enter 3 characters:</b>
    <input type="text" name="threechar" size=3>
    <p><input type="submit" value="done" name="submit1"
       onclick="document.form1.threechar.value=document.form1.threechar.value.touppercase()">
    </form>
    </body>
    </html>
    example 4: submit method. the following example is similar to the previous one, except it submits the form using the submit method instead of a submit object. the form's onsubmit event handler does not prevent the form from being submitted. the form uses a button's onclick event handler to call the checkdata function. if the value is valid, the checkdata function submits the form by calling the form's submit method.

    <html>
    <head>
    <title>form object/submit method example</title>
    </head>
    <script>
    var dataok=false
    function checkdata (){
    if (document.form1.threechar.value.length == 3) {
       document.form1.submit()}
       else {
          alert("enter exactly three characters. " + document.form1.threechar.value +
             " is not valid.")
          return false}
    }
    </script>
    <body>
    <form name="form1" onsubmit="alert('form is being submitted.')">
    <b>enter 3 characters:</b>
    <input type="text" name="threechar" size=3>
    <p><input type="button" value="done" name="button1"
       onclick="checkdata()">
    </form>
    </body>
    </html>

    see also

    button object, checkbox object, fileupload object, hidden object, password object, radio object, reset object, select object, submit object, text object, textarea object; form property


    form property

    property. an object reference specifying the form containing an object.

    syntax

    this.form
    objectreference.form

    parameters

    objectreference specifies an object on a form.

    property of

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

    implemented in

    navigator 2.0

    tainted?

    no

    description

    each form element has a form property that is a reference to the element's parent form. this property is especially useful in event handlers, where you might need to refer to another element on the current form.

    form is a read-only property.

    examples

    example 1. in the following example, the form myform contains a text object and a button. when the user clicks the button, the value of the text object is set to the form's name. the button's onclick event handler uses this.form to refer to the parent form, myform.

    <form name="myform">
    form name:<input type="text" name="text1" value="beluga">
    <p>
    <input name="button1" type="button" value="show form name"
       onclick="this.form.text1.value=this.form.name">
    </form>
    example 2. the following example shows a form with several elements. when the user clicks button2, the function showelements displays an alert dialog box containing the names of each element on the form myform.

    function showelements(theform) {
       str = "form elements of form " + theform.name + ": \n "
       for (i = 0; i < theform.length; i++)
          str += theform.elements[i].name + "\n"
       alert(str)
    }
    </script>
    <form name="myform">
    form name:<input type="text" name="text1" value="beluga">
    <p>
    <input name="button1" type="button" value="show form name"
       onclick="this.form.text1.value=this.form.name">
    <input name="button2" type="button" value="show form elements"
       onclick="showelements(this.form)">
    </form>
    the alert dialog box displays the following text:

    javascript alert:
    form elements of form myform:
    text1
    button1
    button2
    example 3. the following example uses an object reference, rather than the this keyword, to refer to a form. the code returns a reference to myform, which is a form containing mytextobject.

    document.myform.mytextobject.form

    see also

    form object


    forms

    property. an array of objects corresponding to the forms (<form> tags) in a document in source order. see the form object for information.

    tainted?

    yes


    forward

    method. loads the next url in the history list.

    syntax

    history.forward()

    method of

    history object

    implemented in

    navigator 2.0

    description

    this method performs the same action as a user choosing the forward button in the navigator. the forward method is the same as history.go(1).

    examples

    the following custom buttons perform the same operations as the navigator back and forward buttons:

    <p><input type="button" value="< back"
       onclick="history.back()">
    <p><input type="button" value="> forward"
       onclick="history.forward()">

    see also

    back, go methods


    frame

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

    html syntax

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

    <frameset
       rows="rowheightlist"
       cols="columnwidthlist"
       [onblur="handlertext"]
       [onfocus="handlertext"]
       [onload="handlertext"]
       [onunload="handlertext"]>
       <frame src="url" name="framename">
       [ ... <frame src="url" name="framename">]
    </frameset>

    html attributes

    rows="rowheightlist" is a comma-separated list of values specifying the row-height of the frame. an optional suffix defines the units. default units are pixels.

    cols="columnwidthlist" is a comma-separated list of values specifying the column-width of the frame. an optional suffix defines the units. default units are pixels.

    <frame> defines a frame.

    src="url" specifies the url of the document to be displayed in the frame. the url cannot include an anchor name; for example <frame src="doc2.html#colors" name="frame2"> is invalid. see the location object for a description of the url components.

    name="framename" specifies a name to be used as a target of hyperlink jumps. you can access this value using the name property, and you can use this name when indexing the frames array.

    syntax

    to use a frame object's properties:

    1. [windowreference.]framename.propertyname
    2. [windowreference.]frames[index].propertyname
    3. window.propertyname
    4. self.propertyname
    5. parent.propertyname
    to define an onblur or onfocus event handler for a frame (for frames, you cannot specify these event handlers in html):

    1. framereference.onblur=errorhandler
    2. framereference.onfocus=errorhandler

    parameters

    windowreference is a variable windowvar from a window definition (see the window object), or one of the synonyms top or parent.

    framename is the value of the name attribute in the <frame> tag of a frame object.

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

    propertyname is one of the properties listed below.

    framereference is a valid way of referring to a frame.

    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

    the frame object is a property of the window object.

    the frames array is a property of both the frame object and window object.

    implemented in

    description

    the <frameset> tag is used in an html document whose sole purpose is to define the layout of frames that make up a page. each frame is a window object.

    if a <frame> tag contains src and name attributes, you can refer to that frame from a sibling frame by using parent.framename or parent.frames[index]. for example, if the fourth frame in a set has name="homeframe," sibling frames can refer to that frame using parent.homeframe or parent.frames[3].

    the self and window properties are synonyms for the current frame, and you can optionally use them to refer to the current frame. you can use these properties to make your code more readable. see the properties listed below for examples.

    the top and parent properties are also synonyms that can be used in place of the frame name. top refers to the top-most window that contains frames or nested framesets, and parent refers to the window containing the current frameset. see the top and parent properties.

    to create an onblur or onfocus event handler for a frame, you must set the onblur or onfocus property and specify it in all lowercase (you cannot specify it in html).

    the frames array

    you can reference the frame objects in your code by using the frames array. this array contains an entry for each child frame (<frame> tag) in a window containing a <frameset> tag in source order. for example, if a window contains three child frames, these frames are reflected as parent.frames[0], parent.frames[1], and parent.frames[2].

    to use the frames array:

    1. [framereference.]frames[index]
    2. [framereference.]frames.length
    3. [windowreference.]frames[index]
    4. [windowreference.]frames.length
    framereference is a valid way of referring to a frame.

    windowreference is a variable windowvar from a window definition (see the window object), or one of the synonyms top or parent.

    index is an integer representing a frame in a parent window or the name of a frame object as specified by the name attribute.

    to obtain the number of child frames in a window or frame, use the length property:

    [windowreference.].frames.length
    [framereference.].frames.length
    elements in the frames array are read-only. for example, the statement windowreference.frames[0]="frame1" has no effect.

    the value of each element in the frames array is <object nameattribute>, where nameattribute is the name attribute of the frame.

    properties

    the frame object has the following properties:

    property description
    frames
    an array reflecting all the frames in a window
    name
    reflects the name attribute of the <frame> tag
    length
    reflects the number of child frames within a frame
    parent
    a synonym for the window or frame containing the current frameset
    self
    a synonym for the current frame
    window property
    a synonym for the current frame

    the frames array has the following properties:

    property description
    length
    reflects the number of child frames in the document

    methods

    the frame object has the following methods:

  • blur
  • cleartimeout
  • eval
  • focus
  • settimeout
  • tostring
  • valueof
  • event handlers

    the onload and onunload event handlers are specified in the <frameset> tag but are actually event handlers for the window object.

    examples

    the following example creates two windows, each with four frames. in the first window, the first frame contains pushbuttons that change the background colors of the frames in both windows. framset1.html, which defines the frames for the first window, contains the following code:

    <html>
    <head>
    <title>frames and framesets: window 1</title>
    </head>
    <frameset rows="50%,50%" cols="40%,60%"
              onload="alert('hello, world.')">
    <frame src=framcon1.html name="frame1">
    <frame src=framcon2.html name="frame2">
    <frame src=framcon2.html name="frame3">
    <frame src=framcon2.html name="frame4">
    </frameset>
    </html>
    framset2.html, which defines the frames for the second window, contains the following code:

    <html>
    <head>
    <title>frames and framesets: window 2</title>
    </head>
    <frameset rows="50%,50%" cols="40%,60%">
    <frame src=framcon2.html name="frame1">
    <frame src=framcon2.html name="frame2">
    <frame src=framcon2.html name="frame3">
    <frame src=framcon2.html name="frame4">
    </frameset>
    </html>
    framcon1.html, which defines the content for the first frame in the first window, contains the following code:

    <html>
    <body>
    <a name="frame1"><h1>frame1</h1></a>
    <p><a href="framcon3.htm" target=frame2>click here</a>
       to load a different file into frame 2.
    <script>
    window2=open("framset2.htm","secondframeset")
    </script>
    <form>
    <p><input type="button" value="change frame2 to teal"
              onclick="parent.frame2.document.bgcolor='teal'">
    <p><input type="button" value="change frame3 to slateblue"
              onclick="parent.frames[2].document.bgcolor='slateblue'">
    <p><input type="button" value="change frame4 to darkturquoise"
              onclick="top.frames[3].document.bgcolor='darkturquoise'">

    <p><input type="button" value="window2.frame2 to violet"
              onclick="window2.frame2.document.bgcolor='violet'">
    <p><input type="button" value="window2.frame3 to fuchsia"
              onclick="window2.frames[2].document.bgcolor='fuchsia'">
    <p><input type="button" value="window2.frame4 to deeppink"
              onclick="window2.frames[3].document.bgcolor='deeppink'">
    </form>
    </body>
    </html>
    framcon2.html, which defines the content for the remaining frames, contains the following code:

    <html>
    <body>
    <p>this is a frame.
    </body>
    </html>
    framcon3.html, which is referenced in a link object in framcon1.html, contains the following code:

    <html>
    <body>
    <p>this is a frame. what do you think?
    </body>
    </html>

    see also

    document object, window object


    frames

    property. an array of objects corresponding to child frames (<frame> tag) in source order. see the frame object for information.

    tainted?

    no


    function

    object. specifies a string of javascript code to be compiled as a function.

    syntax

    to create a function object:

    functionobjectname = new function ([arg1, arg2, ... argn], functionbody)
    to use a function object:

    functionobjectname.propertyname

    parameters

    functionobjectname is the name of a variable or a property of an existing object. it can also be an object followed by a lowercase event handler name, such as window.onerror. when using function properties, functionobjectname is either the name of an existing function object or a property of an existing object.

    arg1, arg2, ... argn are arguments to be used by the function as formal argument names. each must be a string that corresponds to a valid javascript identifier; for example "x" or "theform".

    functionbody is a string specifying the javascript code to be compiled as the function body.

    propertyname is one of the properties listed below.

    property of

    none

    implemented in

    navigator 3.0

    description

    function objects are evaluated each time they are used. this is less efficient than declaring a function and calling it within your code, because declared functions are compiled.

    in addition to defining functions as described here, you can also use the function statement, as described in "function".

    specifying a variable value with a function object

    the following code assigns a function to the variable setbgcolor. this function sets the current document's background color.

    var setbgcolor = new function("document.bgcolor='antiquewhite'")
    to call the function object, you can specify the variable name as if it were a function. the following code executes the function specified by the setbgcolor variable:

    var colorchoice="antiquewhite"
    if (colorchoice=="antiquewhite") {setbgcolor()}
    you can assign the function to an event handler in either of the following ways:

    1. document.form1.colorbutton.onclick=setbgcolor
    2. <input name="colorbutton" type="button"
          value="change background color"
          onclick="setbgcolor()">
    creating the variable setbgcolor shown above is similar to declaring the following function:

    function setbgcolor() {
       document.bgcolor='antiquewhite'
    }
    assigning a function to a variable is similar to declaring a function, but they have differences:

    specifying arguments in a function object

    the following code specifies a function object that takes two arguments.

    var multfun = new function("x", "y", "return x * y")
    the string arguments "x" and "y" are formal argument names that are used in the function body, "return x * y".

    the following code shows several ways to call the function multfun:

    var theanswer = multfun(7,6)

    document.write("15*2 = " + multfun(15,2))

    <input name="operand1" type="text" value="5" size=5>
    <input name="operand2" type="text" value="6" size=5>
    <input name="result" type="text" value="" size=10>
    <input name="buttonm" type="button" value="multiply"
       onclick="document.form1.result.value=
          multfun(document.form1.operand1.value,
                  document.form1.operand2.value)">
    you cannot call the function multfun in an object's event handler property, because event handler properties cannot take arguments. for example, you cannot call the function multfun by setting a button's onclick property as follows:

    document.form1.button1.onclick=multfun(5,10)

    specifying an event handler with a function object

    the following code assigns a function to a window's onfocus event handler (the event handler must be spelled in all lowercase):

    window.onfocus = new function("document.bgcolor='antiquewhite'")
    once you have a reference to a function object, you can use it like a function and it will convert from an object to a function:

    window.onfocus()
    event handlers do not take arguments, so you cannot declare any arguments in the function() constructor for an event handler.

    properties

    the function object has the following properties:

    property description
    arguments array
    corresponds to elements of a function.
    caller
    specifies which function called the current function
    prototype
    lets you add a properties to a function object.

    methods

    event handlers

    none.

    examples

    example 1. the following example creates onfocus and onblur event handlers for a frame. this code exists in the same file that contains the <frameset> tag. note that this is the only way to create onfocus and onblur event handlers for a frame, because you cannot specify the event handlers in the <frame> tag.

    frames[0].onfocus = new function("document.bgcolor='antiquewhite'")
    frames[0].onblur = new function("document.bgcolor='lightgrey'")
    example 2. you can determine whether a function exists by comparing the function name to null. in the following example, func1 is called if the function nofunc does not exist; otherwise func2 is called. notice that the window name is needed when referring to the function name nofunc.

    if (window.nofunc == null)
       func1()
    else func2()

    getdate

    method. returns the day of the month for the specified date.

    syntax

    dateobjectname.getdate()

    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 value returned by getdate is an integer between one and 31.

    examples

    the second statement below assigns the value 25 to the variable day, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:00")
    day = xmas95.getdate()

    see also

    setdate method


    getday

    method. returns the day of the week for the specified date.

    syntax

    dateobjectname.getday()

    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 value returned by getday is an integer corresponding to the day of the week: zero for sunday, one for monday, two for tuesday, and so on.

    examples

    the second statement below assigns the value 1 to weekday, based on the value of the date object xmas95. this is because december 25, 1995, is a monday.

    xmas95 = new date("december 25, 1995 23:15:00")
    weekday = xmas95.getday()

    gethours

    method. returns the hour for the specified date.

    syntax

    dateobjectname.gethours()

    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 value returned by gethours is an integer between zero and 23.

    examples

    the second statement below assigns the value 23 to the variable hours, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:00")
    hours = xmas95.gethours()

    see also

    sethours method


    getminutes

    method. returns the minutes in the specified date.

    syntax

    dateobjectname.getminutes()

    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 value returned by getminutes is an integer between zero and 59.

    examples

    the second statement below assigns the value 15 to the variable minutes, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:00")
    minutes = xmas95.getminutes()

    see also

    setminutes method


    getmonth

    method. returns the month in the specified date.

    syntax

    dateobjectname.getmonth()

    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 value returned by getmonth is an integer between zero and 11. zero corresponds to january, one to february, and so on.

    examples

    the second statement below assigns the value 11 to the variable month, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:00")
    month = xmas95.getdate()

    see also

    setmonth method


    getseconds

    method. returns the seconds in the current time.

    syntax

    dateobjectname.getseconds()

    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 value returned by getseconds is an integer between zero and 59.

    examples

    the second statement below assigns the value 30 to the variable secs, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:30")
    secs = xmas95.getseconds()

    see also

    setseconds method


    gettime

    method. returns the numeric value corresponding to the time for the specified date.

    syntax

    dateobjectname.gettime()

    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 value returned by the gettime method is the number of milliseconds since 1 january 1970 00:00:00. you can use this method to help assign a date and time to another date object.

    examples

    the following example assigns the date value of thebigday to sameasbigday:

    thebigday = new date("july 1, 1999")
    sameasbigday = new date()
    sameasbigday.settime(thebigday.gettime())

    see also

    settime method


    gettimezoneoffset

    method. returns the time-zone offset in minutes for the current locale.

    syntax

    dateobjectname.gettimezoneoffset()

    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 time-zone offset is the difference between local time and gmt. daylight savings time prevents this value from being a constant.

    examples

    x = new date()
    currenttimezoneoffsetinhours = x.gettimezoneoffset()/60

    getyear

    method. returns the year in the specified date.

    syntax

    dateobjectname.getyear()

    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 getyear method returns either a two-digit or four-digit year:

    examples

    example 1. the second statement below assigns the value 95 to the variable year, based on the value of the date object xmas95.

    xmas95 = new date("december 25, 1995 23:15:00")
    year = xmas95.getyear()
    example 2. the second statement below assigns the value 2026 to the variable theyear, based on the value of the date object newyears2026.

    newyears2026 = new date("2026, january, 1")
    theyear = newyears2026.getyear()

    see also

    setyear method


    go

    method. loads a url from the history list.

    syntax

    history.go(delta | "location")

    parameters

    delta is an integer or a property of an existing object, representing a relative position in the history list.

    location is a string or a property of an existing object, representing all or part of a url in the history list.

    method of

    history object

    implemented in

    navigator 2.0

    description

    the go method navigates to the location in the history list determined by the argument that you specify. you can interactively display the history list by choosing history from the window menu. up to 10 items in the history list are also displayed on the go menu.

    the delta argument is a positive or negative integer. if delta is greater than zero, the go method loads the url that is that number of entries forward in the history list; otherwise, it loads the url that is that number of entries backward in the history list. if delta is zero, navigator reloads the current page.

    the location argument is a string. use location to load the nearest history entry whose url contains location as a substring. the location to url matching is case-insensitive. each section of a url contains different information. see the location object for a description of the url components.

    the go method creates a new entry in the history list. to load a url without creating an entry in the history list, use replace.

    examples

    the following button navigates to the nearest history entry that contains the string "home.netscape.com":

    <p><input type="button" value="go"
       onclick="history.go('home.netscape.com')">
    the following button navigates to the url that is three entries backward in the history list:

    <p><input type="button" value="go"
       onclick="history.go(-3)">

    see also

    back, forward, reload, replace methods


    [next reference file]