|
PropertiesThe following properties are available in JavaScript: (A-L)
action propertyA string specifying a destination URL for form data that is submitted. SyntaxformName.action formName is either the name of a form or an element in the forms array. DescriptionThe action property is a reflection of the ACTION attribute of the <FORM> tag. Each section of a URL contains different information. See the location object for a description of the URL components. You can set the action property at any time. Certain values of the action property may require specific values for other form properties. See RFC 1867 for more information. Property ofExamplesThe following example sets the action property of the musicForm form to the value of the variable urlName: document.musicForm.action=urlName See alsoalinkColor propertyA string specifying the color of an active link (after mouse-button down, but before mouse-button up). Syntaxdocument.alinkColor DescriptionThe alinkColor 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 ALINK attribute of the <BODY> tag. 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". Property ofExamplesThe following example sets the color of active links to aqua using a string literal: document.alinkColor="aqua" The following example sets the color of active links to aqua using a hexadecimal triplet: document.alinkColor="00FFFF" See alsoanchors propertyAn array of objects corresponding to named anchors in source order. See anchor object. appCodeName propertyA string specifying the code name of the browser. Syntaxnavigator.appCodeName DescriptionappCodeName is a read-only property.
Property ofExamplesThe following example displays the value of the appCodeName property: document.write("The value of navigator.appCodeName is " + navigator.appCodeName) For Navigator 2.0, this displays the following: The value of navigator.appCodeName is Mozilla See alsoappName propertyA string specifying the name of the browser. Syntaxnavigator.appName DescriptionappName is a read-only property.
Property ofExamplesThe following example displays the value of the appName property: document.write("The value of navigator.appName is " + navigator.appName) For Navigator 2.0, this displays the following: The value of navigator.appName is Netscape See alsoappVersion propertyA string specifying version information for the Navigator. Syntaxnavigator.appVersion DescriptionThe appVersion property specifies version information in the following format: releaseNumber (platform; country) The values contained in this format are the following: appVersion is a read-only property. Property ofExamplesExample 1. The following example displays version information for the Navigator: document.write("The value of navigator.appVersion is " + navigator.appVersion) For Navigator 2.0 on Windows 95, this displays the following: The value of navigator.appVersion is 2.0 (Win95, I) Example 2. The following example populates a textarea object with newline characters separating each line. Because the newline character varies from platform to platform, the example tests the appVersion property to determine whether the user is running Windows (appVersion contains "Win" for all versions of Windows). If the user is running Windows, the newline character is set to \r\n; otherwise, it's set to \n, which is the newline character for Unix and Macintosh. See alsobgColor propertyA string specifying the color of the document background. Syntaxdocument.bgColor DescriptionThe bgColor 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 BGCOLOR 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 can set the bgColor property at any time. 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".
Property ofExamplesThe following example sets the color of the document background to aqua using a string literal: document.bgColor="aqua" The following example sets the color of the document background to aqua using a hexadecimal triplet: document.bgColor="00FFFF" See alsochecked propertyA Boolean value specifying the selection state of a checkbox object or radio button. Syntax1. checkboxName.checked 2. radioName[index].checked checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.
DescriptionIf a checkbox or radio button is selected, the value of its checked property is true; otherwise, it is false. You can set the checked property at any time. The display of the checkbox or radio button updates immediately when you set the checked property. Property ofExamplesThe following example examines an array of radio buttons called musicType on the musicForm form to determine which button is selected. The VALUE attribute of the selected button is assigned to the checkedButton variable. function stateChecker() { var checkedButton = "" for (var i in document.musicForm.musicType) { if (document.musicForm.musicType[i].checked=="1") { checkedButton=document.musicForm.musicType[i].value } } } See alsocookie propertyString value of a cookie, which is a small piece of information stored by the Navigator in the cookies.txt file. Syntaxdocument.cookie DescriptionUse string methods such as substring, charAt, indexOf, and lastIndexOf to determine the value stored in the cookie. See the Netscape cookie specification for a complete specification of the cookie syntax. You can set the cookie property at any time. Property ofExamplesThe following function uses the cookie property to record a reminder for users of an application. The "expires=" component sets an expiration date for the cookie, so it persists beyond the current browser session. function RecordReminder(time, expression) { // Record a cookie of the form "@<T>=<E>" to map // from <T> in milliseconds since the epoch, // returned by Date.getTime(), onto an encoded expression, // <E> (encoded to contain no white space, semicolon, // or comma characters) document.cookie = "@" + time + "=" + expression + ";" // set the cookie expiration time to one day // beyond the reminder time document.cookie += "expires=" + Date(time + 24*60*60*1000) } When the user loads the page that contains this function, another function uses indexOf("@") and indexOf("=") to determine the date and time stored in the cookie. See alsodefaultChecked propertyA Boolean value indicating the default selection state of a checkbox or radio button. Syntax1. checkboxName.defaultChecked 2. radioName[index].defaultChecked checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.
DescriptionIf an checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute. You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property. Property ofExamplesThe following example resets an array of radio buttons called musicType on the musicForm form to the default selection state. function radioResetter() { var i="" for (i in document.musicForm.musicType) { if (document.musicForm.musicType[i].defaultChecked==true) { document.musicForm.musicType[i].checked=true } } } See alsodefaultSelected propertyA Boolean value indicating the default selection state of an option in a select object. SyntaxselectName.options[index].defaultSelected selectName is either the value of the NAME attribute of a select object or an element in the elements array.
DescriptionIf an option in a select object is selected by default, the value of the defaultSelected property is true; otherwise, it is false. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag; however, setting defaultSelected overrides the SELECTED attribute. You can set the defaultSelected property at any time. The display of the select object does not update when you set the defaultSelected property, only when you set the selected or selectedIndex properties. A select object created without the MULTIPLE attribute can have only one option selected by default. When you set defaultSelected in such an object, any previous default selections, including defaults set with the SELECTED attribute, are cleared. If you set defaultSelected in a select object created with the MULTIPLE attribute, previous default selections are not affected. Property ofoptions array ExamplesIn the following example, the restoreDefault() function returns the musicType select object to its default state. The for loop uses the options array to evaluate every option in the select object. The if statement sets the selected property if defaultSelected is true. function restoreDefault() { for (var i = 0; i < document.musicForm.musicType.length; i++) { if (document.musicForm.musicType.options[i].defaultSelected == true) { document.musicForm.musicType.options[i].selected=true } } }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> See alsodefaultStatus propertyThe default message displayed in the status bar at the bottom of the window. SyntaxwindowReference.defaultStatus windowReference is a valid way of referring to a window, as described in the window object. DescriptionThe defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor. You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOver event handler.
Property ofExamplesIn the following example, the statusSetter() function sets both the status and defaultStatus properties in an onMouseOver event handler: function statusSetter() { window.defaultStatus = "Click the link for the Netscape home page" window.status = "Netscape home page" } <A HREF="http://www.netscape.com" onMouseOver = "statusSetter(); return true">Netscape</A>In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler. See alsodefaultValue propertyA string indicating the default value of a password, text, or textarea object. Syntax1. passwordName.defaultValue 2. textName.defaultValue 3. textareaName.defaultValue passwordName is either the value of the NAME attribute of a password object or an element in the elements array.
DescriptionThe initial value of defaultValue differs for each object: Setting defaultValue programatically overrides the initial setting. If you programatically set defaultValue for the password object and then evaluate it, JavaScript returns the current value. You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property. Property ofhidden, password, text, textarea ExamplesThe following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window: function defaultGetter() { msgWindow=window.open("") msgWindow.document.write("hidden.defaultValue is " + document.surfCity.hiddenObj.defaultValue + "<BR>") msgWindow.document.write("password.defaultValue is " + document.surfCity.passwordObj.defaultValue + "<BR>") msgWindow.document.write("text.defaultValue is " + document.surfCity.textObj.defaultValue + "<BR>") msgWindow.document.write("textarea.defaultValue is " + document.surfCity.textareaObj.defaultValue + "<BR>") msgWindow.document.close() } See alsoE propertyEuler's constant and the base of natural logarithms, approximately 2.718. SyntaxMath.E DescriptionBecause E is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays Euler's constant: document.write("Euler's constant is " + Math.E) See alsoelements propertyAn array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order. See elements array. encoding propertyA string specifying the MIME encoding of the form. SyntaxformName.encoding formName is either the name of a form or an element in the forms array. DescriptionThe encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute. You can set the encoding property at any time. Certain values of the encoding property may require specific values for other form properties. See RFC 1867 for more information. Property ofExamplesThe following function returns the value of the musicForm encoding property: function getEncoding() { return document.musicForm.encoding } See alsofgColor propertyA string specifying the color of the document text. Syntaxdocument.fgColor DescriptionThe 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:
Property ofExamplesThe 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 alsoforms propertyAn array of objects corresponding to the forms (<FORM> tags) in a document in source order. See form object. frames propertyAn array of objects corresponding to child frames (<FRAME> tag) in source order. See frame object. hash propertyA string beginning with a hash mark (#) that specifies an anchor name in the URL. Syntaxlocation.hash DescriptionThe hash property specifies a portion of the URL. You can set the hash property at any time, although it is safer to set the href property to change a location. If the hash that you specify cannot be found in the current location, you will get an error. See RFC 1738> for complete information about the hash.
Property ofExamplesSee the examples for the anchor object and the href property. See alsohost propertyA string specifying the hostname:port portion of the URL. Syntaxlocation.host DescriptionThe host property specifies a portion of the URL. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is null, the host property is the same as the hostname property. You can set the host property at any time, although it is safer to set the href property to change a location. If the host that you specify cannot be found in the current location, you will get an error. See Section 3.1 of RFC 1738 for complete information about the hostname and port.
Property ofExamplesSee the examples for the href property. See alsohostname propertyA string specifying the host and domain name, or IP address, of a network host. Syntaxlocation.hostname DescriptionThe hostname property specifies a portion of the URL. The hostname property is a substring of the host property. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is null, the host property is the same as the hostname property. You can set the hostname property at any time, although it is safer to set the href property to change a location. If the hostname that you specify cannot be found in the current location, you will get an error. See Section 3.1 of RFC 1738 for complete information about the hostname.
Property ofExamplesSee the examples for the href property. See alsohref propertyA string specifying the entire URL. Syntaxlocation.href DescriptionThe href property specifies the entire URL. Other location object properties are substrings of the href property. You can set the href property at any time. See RFC 1738 for complete information about the URL.
Property ofExamplesIn the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow. newWindow=window.open ("http://home.netscape.com/comprod/products/navigator/ version_2.0/script/script_info/objects.html#checkbox_object") msgWindow.document.write("newWindow.location.href = " + newWindow.location.href + "<P>") msgWindow.document.write("newWindow.location.protocol = " + newWindow.location.protocol + "<P>") msgWindow.document.write("newWindow.location.host = " + newWindow.location.host + "<P>") msgWindow.document.write("newWindow.location.hostName = " + newWindow.location.hostName + "<P>") msgWindow.document.write("newWindow.location.port = " + newWindow.location.port + "<P>") msgWindow.document.write("newWindow.location.pathname = " + newWindow.location.pathname + "<P>") msgWindow.document.write("newWindow.location.search = " + newWindow.location.search + "<P>") msgWindow.document.write("newWindow.location.hash = " + newWindow.location.hash + "<P>") msgWindow.document.close() The previous example displays output such as the following: newWindow.location.href = http://home.netscape.com/comprod/products/navigator/ version_2.0/script/script_info/objects.html#checkbox_object newWindow.location.protocol = http: newWindow.location.host = home.netscape.com newWindow.location.hostName = home.netscape.com newWindow.location.port = newWindow.location.pathname = /comprod/products/navigator/version_2.0/script/ script_info/objects.html newWindow.location.search = newWindow.location.hash = #checkbox_object See alsoindex propertyAn integer representing the index of an option in a select object. SyntaxselectName.options[indexValue].index selectName is either the value of the NAME attribute of a select object or an element in the elements array.
DescriptionThe number identifying the position of the option in the selection, starting from zero. Property ofoptions array See alsolastModified propertyA string representing the date that a document was last modified. Syntaxdocument.lastModified DescriptionlastModified is a read-only property. Property ofExamplesIn the following example, the lastModified property is used in a <SCRIPT> tag at the end of an HTML file to display the modification date of the page: document.write("This page updated on " + document.lastModified) length propertyAn integer that specifies a length-related feature of the calling object or array. SyntaxWhen used with objects: 1. formName.length 2. frameReference.length 3. history.length 4. radioName.length 5. selectName.length 6. stringName.length 7. windowReference.length When used with array properties: 8. anchors.length 9. elements.length 10. forms.length 11. frameReference.frames.length 12. windowReference.frames.length 13. links.length 14. selectName.options.length formName is either the name of a form or an element in the forms array.
DescriptionThe length property is an integer that specifies one of the following: length is always a read-only property. For a null string, length is zero. For a select object, the values returned by form 5 and form 14 of the syntax are the same. For a window containing frames, the values returned by form 7 and form 12 of the syntax are the same. For a form object, the values returned by form 1 and form 9 of the syntax are the same. For a frame containing frames, the values returned by form 2 and form 11 of the syntax are the same. Property ofExamplesIn the following example, the getChoice() function uses the length property to iterate over every element in the musicType array. musicType is a select element on the musicForm form. 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 } } } The following example displays 8 in an alert dialog box: var x="Netscape" alert("The string length is " + x.length) linkColor propertyA string specifying the color of the document hyperlinks. Syntaxdocument.linkColor DescriptionThe linkColor 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 LINK 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".
Property ofExamplesThe following example sets the color of document links to aqua using a string literal: document.linkColor="aqua" The following example sets the color of document links to aqua using a hexadecimal triplet: document.linkColor="00FFFF" See alsolinks propertyAn array of objects corresponding to link objects in source order. See link object. LN2 propertyThe natural logarithm of two, approximately 0.693. SyntaxMath.LN2 DescriptionBecause LN2 is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the natural log of 2: document.write("The natural log of 2 is " + Math.LN2) See alsoLN10 propertyThe natural logarithm of ten, approximately 2.302. SyntaxMath.LN10 DescriptionBecause LN10 is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the natural log of 10: document.write("The natural log of 10 is " + Math.LN10) See alsolocation propertyA string specifying the complete URL of the document. Syntaxdocument.location DescriptionDo not confuse the location property of the document object with the location object. You cannot change the value of the location property (document.location), but you can change the value of the location object's properties (window.location.propertyName). document.location is a string-valued property that usually matches what window.location is set to when you load the document, but redirection may change it. location is a read-only property of document. Property ofExamplesThe following example displays the URL of the current document: document.write("The current URL is " + document.location) See alsoLOG2E propertyThe base 2 logarithm of e (approximately 1.442). SyntaxMath.LOG2E DescriptionBecause LOG2E is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the base 2 logarithm of E: document.write("The base 2 logarithm of E is " + Math.LOG2E) See alsoLOG10E propertyThe base 10 logarithm of e (approximately 0.434). SyntaxMath.LOG10E DescriptionBecause LOG10E is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the base 10 logarithm of E: document.write("The base 10 logarithm of E is " + Math.LOG10E) See also(M-Z)
method propertyA string specifying how form field input information is sent to the server. SyntaxformName.method formName is either the name of a form or an element in the forms array. DescriptionThe method property is a reflection of the METHOD attribute of the <FORM> tag. The method property should evaluate to either "get" or "post". You can set the method property at any time. Certain values of the method property may require specific values for other form properties. See RFC 1867 for more information. Property ofExamplesThe following function returns the value of the musicForm method property: function getMethod() { return document.musicForm.method } See alsoname propertyA string specifying the name of an object. Syntax1. objectName.name 2. frameReference.name 3. frameReference.frames.name 4. radioName[index].name 5. selectName.options.name 6. windowReference.name 7. windowReference.frames.name objectName is either the value of the NAME attribute of any of the objects listed below or an element in the elements array.
DescriptionThe value of the name property differs between the window object and other objects. window objectThe name property for the window object is represented by form 6 and form 7 of the syntax. The name property represents the value of the windowName argument described in the window object syntax. Both forms of the syntax represent the same value. name is a read-only property. All other objectsThe name property for all objects except window is represented by forms 1 through 5 of the syntax. For all objects except window, the name property initially reflects the value of the NAME attribute. Changing the name property overrides this setting. You can set the name property at any time. The name property is the same for every radio button in a single radio object. Individual radio buttons are referenced by their position in the radio array. Do not confuse the name property with the label displayed on a button, reset, or submit object. The value property specifies the label for these objects. The name property is not displayed onscreen; it is used to reference the objects programatically. For a select object, the values specified by form 1 and form 5 of the syntax are the same. For a frame object, the values specified by forms 1, 2, and 3 of the syntax are the same. If multiple objects on the same form have the same NAME attribute, an array of the given name is created automatically. Each element in the array represents an individual form object. Elements are indexed in source order starting at 0. For example, if two text elements and a textarea element on the same form have their NAME attribute set to "myField", an array with the elements myField[0], myField[1], and myField[2] is created. Property ofExamplesIn the following example, the valueGetter() function uses a for loop to iterate over the array of elements on the valueTest form. The msgWindow window displays the names of all the elements on the form: newWindow=window.open("http://www.netscape.com") function valueGetter() { var msgWindow=window.open("") for (var i = 0; i < newWindow.document.valueTest.elements.length; i++) { msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>") } }In the following example, the first statement creates a window called netscapeWin. The second statement displays the value "netscapeHomePage" in the alert dialog box, because "netscapeHomePage" is the value of the windowName argument of netscapeWin. netscapeWin=window.open("http://www.netscape.com", "netscapeHomePage") alert(netscapeWin.name) See alsoFor button, reset, and submit: options propertyAn array corresponding to options in a select object (<OPTION> tags) in source order. See select object. parent propertyThe parent property is a synonym for a window whose frameset contains the current frame. Syntax1. parent.propertyName 2. parent.methodName 3. top.frameName 4. top.frames[index] propertyName is the defaultStatus, status, length, name, or parent property when the calling parent refers to a window object.
DescriptionThe parent property refers to the <FRAMESET> window of a frame. Child frames within a frameset refer to sibling frames by using "parent" in place of the window name as follows: 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]. You can use parent.parent to refer to the "grandparent" frame or window when a <FRAMESET> tag is nested within a child frame. The parent property is read-only. The value of the parent property is <object nameAttribute>where nameAttribute is the NAME attribute if the parent is a frame, or an internal reference if the parent is a window. Property ofExamplesSee the examples for the frame object. pathname propertyA string specifying the url-path portion of the URL. Syntaxlocation.pathname DescriptionThe pathname property specifies a portion of the URL. The pathname supplies the details of how the specified resource can be accessed. You can set the pathname property at any time, although it is safer to set the href property to change a location. If the pathname that you specify cannot be found in the current location, you will get an error. See Section 3.1 of RFC 1738 for complete information about the pathname.
Property ofExamplesSee the examples for the href property. See alsoPI propertyThe ratio of the circumference of a circle to its diameter, approximately 3.14159. SyntaxMath.PI DescriptionBecause PI is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the value of pi: document.write("The value of pi is " + Math.PI) See alsoport propertyA string specifying the communications port that the server uses for communications. Syntaxlocation.port DescriptionThe port property specifies a portion of the URL. The port property is a substring of the host property. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is not defined, the host property is the same as the hostname property. You can set the port property at any time, although it is safer to set the href property to change a location. If the port that you specify cannot be found in the current location, you will get an error. If the port property is not specified, it defaults to 80 on the server. See Section 3.1 of RFC 1738 for complete information about the port.
Property ofExamplesSee the examples for the href property. See alsoprotocol propertyA string specifying the beginning of the URL, up to and including the first colon. Syntaxlocation.protocol DescriptionThe protocol property specifies a portion of the URL. The protocol indicates the access method of the URL. For example, a protocol of "http:" specifies Hypertext Transfer Protocol, and a protocol of "javascript:" specifies JavaScript code. You can set the protocol property at any time, although it is safer to set the href property to change a location. If the protocol that you specify cannot be found in the current location, you will get an error. The protocol property represents the scheme name of the URL. See Section 2.1 of RFC 1738 for complete information about the protocol.
Property ofExamplesSee the examples for the href property. See alsoreferrer propertySpecifies the URL of the calling document when a user clicks a link. Syntaxdocument.referrer DescriptionWhen a user navigates to a destination document by clicking a link object on a source document, the referrer property contains the URL of the source document. Evaluate the referrer property from the destination document. referrer is a read-only property. Property ofExamplesIn the following example, the getReferrer() function is called from the destination document. It returns the URL of the source document. function getReferrer() { return document.referrer } search propertyA string beginning with a question mark that specifies any query information in the URL. Syntaxlocation.search DescriptionThe search property specifies a portion of the URL. You can set the search property at any time, although it is safer to set the href property to change a location. If the search that you specify cannot be found in the current location, you will get an error. See Section 3.3 of RFC 1738 for complete information about the search.
Property ofExamplesIn the following example, the window.open statement creates a window called newWindow and loads the specified URL into it. The document.write statements display all the properties of newWindow.location in a window called msgWindow. newWindow=window.open ("http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW") msgWindow.document.write("newWindow.location.href = " + newWindow.location.href + "<P>") msgWindow.document.write("newWindow.location.protocol = " + newWindow.location.protocol + "<P>") msgWindow.document.write("newWindow.location.host = " + newWindow.location.host + "<P>") msgWindow.document.write("newWindow.location.hostName = " + newWindow.location.hostName + "<P>") msgWindow.document.write("newWindow.location.port = " + newWindow.location.port + "<P>") msgWindow.document.write("newWindow.location.pathname = " + newWindow.location.pathname + "<P>") msgWindow.document.write("newWindow.location.search = " + newWindow.location.search + "<P>") msgWindow.document.write("newWindow.location.hash = " + newWindow.location.hash + "<P>") msgWindow.document.close() The previous example displays the following output: newWindow.location.href = http://guide-p.infoseek.com/WW/NS/Titles?qt=RFC+1738+&col=WW newWindow.location.protocol = http: newWindow.location.host = guide-p.infoseek.com newWindow.location.hostName = guide-p.infoseek.com newWindow.location.port = newWindow.location.pathname = /WW/NS/Titles newWindow.location.search = ?qt=RFC+1738+&col=WW newWindow.location.hash = See alsoselected propertyA Boolean value specifying the current selection state of an option in a select object. SyntaxselectName.options[index].selected selectName is either the value of the NAME attribute of a select object or an element in the elements array.
DescriptionIf an option in a select object is selected, the value of its selected property is true; otherwise, it is false. You can set the selected property at any time. The display of the select object updates immediately when you set the selected property. In general, the selected property is more useful than the selectedIndex property for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options. Property ofoptions array ExamplesSee the examples for the defaultSelected property. See alsoselectedIndex propertyAn integer specifying the index of the selected option in a select object. Syntax1. selectName.selectedIndex 2. selectName.options.selectedIndex selectName is either the value of the NAME attribute of a select object or an element in the elements array. DescriptionOptions in a select object are indexed in the order in which they are defined, starting with an index of 0. You can set the selectedIndex property at any time. The display of the select object updates immediately when you set the selectedIndex property. Both forms of the syntax specify the same value. In general, the selectedIndex property is more useful for select objects that are created without the MULTIPLE attribute. If you evaluate selectedIndex when multiple options are selected, the selectedIndex property specifies the index of the first option only. Setting selectedIndex clears any other options that are selected in the select object. The selected property of the select object's options array is more useful for select objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options. Property ofExamplesIn the following example, the getSelectedIndex() function returns the selected index in the musicType select object: function getSelectedIndex() { return document.musicForm.musicType.selectedIndex }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> See alsoself propertyThe self property is a synonym for the current window or frame. Syntax1. self.propertyName 2. self.methodName propertyName is the defaultStatus, status, length, or name property when self refers to a window object.
DescriptionThe self property refers to the current window or frame. Use the self property to disambiguate a window property from a form or form element of the same name. You can also use the self property to make your code more readable. The self property is read-only. The value of the self property is <object nameAttribute>where nameAttribute is the NAME attribute if self refers to a frame, or an internal reference if self refers to a window. Property ofExamplesIn the following example, self.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 or form element called "status" within the current window. See alsoSQRT1_2 propertyThe square root of one-half; equivalently, one over the square root of two, approximately 0.707. SyntaxMath.SQRT1_2 DescriptionBecause SQRT1_2 is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays 1 over the square root of 2: document.write("1 over the square root of 2 is " + Math.SQRT1_2) See alsoSQRT2 propertyThe square root of two, approximately 1.414. SyntaxMath.SQRT2 DescriptionBecause SQRT2 is a constant, it is a read-only property of Math. Property ofExamplesThe following example displays the square root of 2: document.write("The square root of 2 is " + Math.SQRT2) See alsostatus propertySpecifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor. SyntaxwindowReference.status windowReference is a valid way of referring to a window, as described in the window object. DescriptionDo not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar. You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler.
Property ofExamplesSuppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property: In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler. See alsotarget propertyFor 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. Syntax1. formName.target 2. linkName.target formName is either the name of a form or an element in the forms array.
DescriptionThe target property initially reflects the TARGET attribute of the <FORM> and <A> tags; however, setting target overrides these attributes. The target property cannot be assigned the value of a JavaScript expression or variable. You can set the target property at any time. Certain values of the target property may require specific values for other form properties. See RFC 1867 for more information. Property ofExamplesThe following example specifies that responses to the musicInfo form are displayed in the "msgWindow" window: document.musicInfo.target="msgWindow" See alsoFor form: text propertyA string specifying the text that follows an <OPTION> tag in a select object. SyntaxselectName.options[index].text selectName is either the value of the NAME attribute of a select object or an element in the elements array.
DescriptionThe text property initially reflects the text that follows an <OPTION> tag in a select object. You can set the text property at any time; however, the following effects result: Be careful if you change the text property. If you evaluate the property after you change it, the property contains the new value, not the value that is displayed onscreen. Property ofoptions array ExamplesIn 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> title propertyA string representing the title of a document. Syntaxdocument.title DescriptionThe 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. Property ofExamplesIn the following example, the value of the title property is assigned to a variable called docTitle: var newWindow = window.open("http://www.netscape.com") var docTitle = newWindow.document.title top propertyThe top property is a synonym for the top-most Navigator window, which is a "document window" or "Web Browser window." Syntax1. top.propertyName 2. top.methodName 3. top.frameName 4. top.frames[index] propertyName is defaultStatus, status, or length.
DescriptionThe 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. Property ofExamplesThe statement top.close() closes the top-most ancestor window. The statement top.length specifies the number of frames contained within the top-most ancestor window. When the top-most ancestor is defined as follows, top.length returns 3: <FRAMESET COLS="30%,40%,30%"> <FRAME SRC=child1.htm NAME="childFrame1"> <FRAME SRC=child2.htm NAME="childFrame2"> <FRAME SRC=child3.htm NAME="childFrame3"> </FRAMESET> The following example sets the background color of a frame called myFrame to red. myFrame is a child of the top-most ancestor window. top.myFrame.document.bgColor="red" userAgent propertyA string representing the value of the user-agent header sent in the HTTP protocol from client to server. Syntaxnavigator.userAgent DescriptionServers use the value sent in the user-agent header to identify the client. userAgent is a read-only property. Property ofExamplesThe 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 alsovalue propertyA string that is related to the VALUE attribute of its object. Syntax1. objectName.value 2. radioName[index].value 3. selectName.options.[index].value objectName is either the value of the NAME attribute of a hidden, password, text, textarea, button, reset, submit or checkbox object or an element in the elements array.
DescriptionThe value property differs for every object. hidden, text, and textarea objectsThe 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 objectThe value property is a string that initially reflects the VALUE attribute. This string is represented by asterisks in the password object field. The value of this property changes when a user or a program modifies the field, but the value is always displayed as asterisks. If you programatically set the value property and then evaluate it, JavaScript returns the current value. If a user interactively modifies the value in the password field, you cannot evaluate it accurately for security reasons. button, reset, and submit objectsWhen 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 onscreen; it is used to reference the objects programatically. options arrayThe value property is a string that initially reflects the VALUE attribute. The value of this property can change when a program modifies it. The value property is not displayed onscreen, but is returned to the server if the option is selected. You can set the value property at any time. Do not confuse the value property with the selection state of the select object or the text that is displayed as an option. The selected and selectedIndex properties determine which options are selected, and the defaultSelected property determines the default selection state. The text that is displayed in each option is specified by its text property. checkbox and radio objectsWhen a VALUE attribute is specified in HTML, the value property is a string that reflects it. When a VALUE attribute is not specified in HTML, the value property is a string that evaluates to "on". The value property is not displayed onscreen, but is returned to the server if the radio button or checkbox is selected. You can set the value property at any time. Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. The checked property determines the selection state of the object, and the defaultChecked property determines the default selection state. The text that is displayed is specified following the <INPUT TYPE="checkbox"> or the <INPUT TYPE="radio"> tag. Property ofExamplesThe 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 alsoFor hidden, password, text, and textarea: For button, reset, and submit: For options array: For checkbox and radio: vlinkColor propertyA string specifying the color of visited links. Syntaxdocument.vlinkColor DescriptionThe 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".
Property ofExamplesThe 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 alsowindow propertyThe window property is a synonym for the current window or frame. Syntax1. window.propertyName 2. window.methodName propertyName is the defaultStatus, status, length, or name property when the calling window refers to a window object.
DescriptionThe 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. Property ofExamplesIn 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. See also |