The following entries summarize the various JavaScript objects and independent functions. The properties, constants, arrays, methods, functions, and event handlers for each object are described in the entry for that object. Thus, if you want to read about the write() method of the Document object (Document.write), look it up in the entry for Document.
If you can't remember what object a method or property, etc., goes with, the following table should help. The left column lists the names of all the functions, properties, etc., and the right column gives the name of the object(s) with which they are associated. Since this table serves as something of a table of contents for this section, object names themselves also appear in the left hand column.
We've tried to cram as much useful information as possible into this chapter. But JavaScript has many intricacies to which we cannot do justice in so short a format. For more complete reference information, as well as an excellent guide to using the language, see JavaScript: The Definitive Guide.
For | See Object | For | See Object |
---|---|---|---|
abs( ) | Math | cookie | Document |
acos( ) | Math | cos( ) | Math |
action | Form | current | History |
alert( ) | Window | Date | Date |
alinkColor | Document | defaultChecked | Checkbox |
Anchor | Anchor | Radio | |
anchor( ) | String | defaultSelected | Option |
anchors[ ] | Document | defaultStatus | Window |
appCodeName | Navigator | defaultValue | Text |
applets[ ] | Document | Textarea | |
appName | Navigator | description | MimeType |
appVersion | Navigator | Plugin | |
arguments[ ] | Function | Document | Document |
Array | Array | document | Window |
asin( ) | Math | domain | Document |
assign( ) | Object | E | Math |
atan( ) | Math | Element | Element |
atan2( ) | Math | elements[ ] | Form |
back( ) | History | embeds[ ] | Document |
bgColor | Document | enabledPlugin | MimeType |
big( ) | String | encoding | Form |
blink( ) | String | escape( ) | escape( ) |
blur( ) | FileUpload | eval( ) | eval( ) |
Password | Object | ||
Text | exp( ) | Math | |
Textarea | fgColor | Document | |
Window | FileUpload | FileUpload | |
bold( ) | String | filename | Plugin |
Boolean | Boolean | fixed( ) | String |
border | Image | floor( ) | Math |
Button | Button | focus( ) | FileUpload |
caller | Function | Password | |
ceil( ) | Math | Text | |
charAt( ) | String | Textarea | |
Checkbox | Checkbox | Window | |
checked | Checkbox | fontcolor( ) | String |
Radio | fontsize( ) | String | |
clear( ) | Document | Form | Form |
clearTimeout( ) | Window | form | Button |
close( ) | Document | Checkbox | |
Window | Element | ||
closed | Window | FileUpload | |
complete | Image | Hidden | |
confirm( ) | Window | Password | |
form (cont'd) | Radio | length (cont'd) | JavaArray |
Reset | Select | ||
Select | String | ||
Submit | Window | ||
Text | Link | Link | |
Textarea | link( ) | String | |
forms[ ] | Document | linkColor | Document |
forward( ) | History | links[ ] | Document |
Frame | Frame | LN10 | Math |
frames[ ] | Window | LN2 | Math |
Function | Function | location | Document |
getClass( ) | getClass( ) | Location | Location |
getDate( ) | Date | location | Window |
getDay( ) | Date | log( ) | Math |
getHours( ) | Date | LOG10E | Math |
getMinutes( ) | Date | LOG2E | Math |
getMonth( ) | Date | lowsrc | Image |
getSeconds( ) | Date | Math | Math |
getTime( ) | Date | max( ) | Math |
getTimezoneOffset( ) | Date | MAX_VALUE | Number |
getYear( ) | Date | method | Form |
go( ) | History | MimeType | MimeType |
hash | Location | mimeTypes | Navigator |
height | Image | mimeTypes[ ] | Plugin |
Hidden | Hidden | min( ) | Math |
History | History | MIN_VALUE | Number |
history | Window | name | Button |
host | Location | Checkbox | |
hostname | Location | Element | |
href | Location | FileUpload | |
hspace | Image | Hidden | |
Image | Image | Image | |
images[ ] | Document | MimeType | |
index | Option | Password | |
indexOf( ) | String | Plugin | |
isNaN( ) | isNaN( ) | Radio | |
italics( ) | String | Reset | |
java | java | Select | |
Packages | Submit | ||
JavaArray | JavaArray | Text | |
JavaClass | JavaClass | Textarea | |
javaEnabled( ) | Navigator | Window | |
JavaObject | JavaObject | NaN | Number |
JavaPackage | JavaPackage | Navigator | Navigator |
join( ) | Array | navigator | navigator |
lastIndexOf( ) | String | NEGATIVE_INFINITY | Number |
lastModified | Document | netscape | netscape |
length | Array | Packages | |
History | next | History | |
Number | Number | previous | History |
Object | Object | prompt( ) | Window |
onabort( ) | Image | protocol | Location |
onblur( ) | FileUpload | prototype | Function |
Text | Radio | Radio | |
Textarea | random( ) | Math | |
Window | referrer | Document | |
onchange( ) | FileUpload | reload( ) | Location |
Select | replace( ) | Location | |
Text | Reset | Reset | |
Textarea | reset( ) | Form | |
onclick( ) | Button | reverse( ) | Array |
Checkbox | round( ) | Math | |
Link | scroll( ) | Window | |
Radio | search | Location | |
Reset | Select | Select | |
Submit | select( ) | Text | |
onerror( ) | Image | selected | Option |
Window | selectedIndex | Select | |
onfocus( ) | FileUpload | self | Window |
Text | setDate( ) | Date | |
Textarea | setHours( ) | Date | |
Window | setMinutes( ) | Date | |
onload( ) | Image | setMonth( ) | Date |
Window | setSeconds( ) | Date | |
onmouseout( ) | Link | setTime( ) | Date |
onmouseover( ) | Link | setTimeout( ) | Window |
onreset( ) | Form | setYear( ) | Date |
onsubmit( ) | Form | sin( ) | Math |
onunload( ) | Window | small( ) | String |
open( ) | Document | sort( ) | Array |
Window | split( ) | String | |
opener | Window | sqrt( ) | Math |
Option | Option | SQRT1_2 | Math |
options[ ] | Select | SQRT2 | Math |
Packages | Packages | src | Image |
parent | Window | status | Window |
parse( ) | Date | strike( ) | String |
parseFloat( ) | parseFloat( ) | String | String |
parseInt( ) | parseInt( ) | sub( ) | String |
Password | Password | Submit | Submit |
pathname | Location | submit( ) | Form |
PI | Math | substring( ) | String |
Plugin | Plugin | suffixes | MimeType |
plugins | Document | sun | Packages |
Navigator | sun | ||
port | Location | sup( ) | String |
POSITIVE_INFINITY | Number | taint( ) | taint( ) |
pow( ) | Math | taintEnabled( ) | Navigator |
tan( ) | Math | UTC( ) | Date |
target | Form | value | Button |
Link | Checkbox | ||
text | Option | Element | |
Text | Text | FileUpload | |
Textarea | Textarea | Hidden | |
title | Document | Option | |
toGMTString( ) | Date | Password | |
toLocaleString( ) | Date | Radio | |
toLowerCase( ) | String | Reset | |
top | Window | Submit | |
toString( ) | Boolean | Text | |
Function | Textarea | ||
Number | valueOf( ) | Object | |
Object | vlinkColor | Document | |
toUpperCase( ) | String | vspace | Image |
type | Element | width | Image |
Select | Window | Window | |
unescape( ) | unescape( ) | window | Window |
untaint( ) | untaint( ) | write( ) | Document |
URL | Document | writeln( ) | Document |
userAgent | Navigator |
Represents a named position (of an HTML document) that may be the target or destination of a hypertext link. A hypertext link may refer to an anchor by using its name after a # character in a URL. In Netscape 2.0, the elements of the document.anchor[] array are set to null, so it is not possible to actually obtain an Anchor object. See also Document.Link.
document.anchors.length // number of anchors in the document document.anchors[i] // one of the Anchor objects
An Anchor object is created by any standard HTML <a> tag that contains a <name> attribute:
<a name="anchor_name" links may refer to this anchor by this name [ href=URL ] an anchor may also be a link [ target="window_name" ] links may refer to other windows > anchor HTML text </a>
Creates and initializes an array. Along with the usual array capabilities that all JavaScript objects have, the Array object provides additional array functionality: a constructor function for initializing arrays, an automatically updated length field that stores the size of the array, and join(), reverse(), and sort() methods that manipulate the elements of an array. Available in Netscape 3.0. See also Object.
new Array() with no arguments, length field is set to 0 new Array(size) size = number of elements; sets length new Array(element0, element1, ..., elementn) length set to number of elements
Read/write integer specifying the number of elements in the array, or, when the array does not have contiguous elements, a number one larger than the index of the last element in the array. The length property of a new array is initialized when the array is created with the Array() constructor method. Adding new elements to an array created with the Array() constructor updates the length, if necessary:
a = new Array(); a.length initialized to 0 b = new Array(10); b.length initialized to 10 c = new Array("one", "two", "three"); c.length initialized to 3 c[3] = "four"; c.length updated to 4 c[10] = "blastoff"; c.length becomes 11
You can also set the value of the length property to change the size of an array (i.e., truncate elements or add "undefined" ones).
Converts each of the elements of an array to a string, and then concatenates those strings, inserting the specified separator string between the elements. Returns the resulting string. You can split a string up into array elements--with the split() method of the String object.
array.join() array.join(separator) if no separator, the empty string is used
Reverse, in place (i.e., without creating a new array), the order of the elements of an array.
With no arguments, sorts alphabetically (by character encoding); elements are first converted to strings, if necessary, so that they can be compared. To sort the array elements in some other order, you must supply a function that compares two values and returns a number indicating their relative order.
array.sort() array.sort(orderfunc) orderfunc - optional comparison function
The comparison function should take two arguments, a and b, and should:
An object wrapper around the boolean value; exists solely to provide a toString() method to convert boolean values to strings. When the toString() method is invoked to convert a boolean value to a string (and it is often invoked implicitly by JavaScript), JavaScript internally converts the boolean value to a transient Boolean object, on which the method can be invoked.
You can create Boolean objects that are not transient by calling the Boolean() constructor method:
new Boolean(value)
The argument is the value to be held by the Boolean object. This will be converted to a boolean value, if necessary. The values 0, null, and the empty string "" are all converted to false. All other values, including the string "false," are converted to true. Available in Netscape 3.0. See also Object.
Returns true or false, depending on the boolean value represented by the Boolean object.
Returns the boolean value represented by the Boolean object.
Represents a graphical pushbutton in a form within an HTML document. Use a Button object whenever you want to allow the user to trigger some action on your Web page. Note that the Submit and Reset objects are types of Button objects that submit a form and reset a form's values. Often these default actions are sufficient for a form, and you do not need to create any other types of buttons. Available in Netscape 2.0; enhanced in 3.0. See also Element, Form, Reset, Submit.
form.button_name form.elements[i] form.elements['button_name']
Read-only reference to the Form object that contains the specified button object.
Set by the name attribute of the HTML <input> tag that creates the button, this read-only string property provides the name of the button.
form.button_name form.elements['button_name']
See the type property of the Element object (Element.type).
Set by the value attribute of the HTML <input> tag that creates the button, this read-only string property provides text displayed in the Button object.
Invoked when the button is clicked; defined by the onClick attribute of the HTML <input> tag. Value may be any number of JavaScript statements, separated by semicolons, that are executed when the user clicks the button.
<INPUT TYPE="button" a definition of the handler value="button-text" onClick="handler-statements"> button.onclick a reference to the handler button.onclick() an explicit invocation of the handler
A Button object is created with a standard HTML <input> tag, with the addition of the onClick attribute:
<form> ... <input type="button" specifies that this is a button value="label" the text that is to appear within the button; specifies the value property [ name="name" ] a name that can later be used to refer to the button; specifies the name property [ onClick="handler" ] JavaScript statements to be executed when the button is clicked > ... </form>
Represents a single graphical checkbox in an HTML form. Note that the text that appears next to the checkbox is not part of the Checkbox object itself, and must be specified external to the Checkbox's HTML <input> tag. The onClick event handler allows you to specify JavaScript code to be executed when the Checkbox is checked or "un-checked." The value of the checked property gives the state of the Checkbox; it can also be set to change the state. Available but buggy in Netscape 2.0; enhanced in 3.0. See also Element, Form, Radio.
A Checkbox object with a unique name may be referenced in any of these ways:
form.checkbox_name form.elements[i] form.elements['checkbox_name']
When a form contains a group of checkboxes with the same name, they are placed in an array, and may be referenced as follows:
form.checkbox_name[j] form.checkbox_name.length form.elements[i][j] form.elements[i].length form.elements['checkbox_name'][j] form.elements['checkbox_name'].length
Read/write Boolean property that specifies whether the Checkbox is checked (true) or not (false). Setting the checked property changes the appearance of the Checkbox but does not cause the onclick() event handler to be invoked.
Read-only Boolean property that represents the Checkbox's initial state. May be specified using the checked attribute in the HTML <input> tag. Can be used to reset a Checkbox to its default state.
Read-only reference to the Form object that contains the Checkbox.
Read-only string, set by the HTML name attribute, that specifies the name of the Checkbox object (or array of Checkbox objects).
See the type property of the Element object (Element.type).
Read/write string that specifies the text that is passed to the Web server if the Checkbox is checked when the form is submitted. The initial value of value is specified by the HTML value attribute. If no value attribute is specified, then the default value string is "on."
Invoked when the user clicks on a Checkbox; it is defined by the HTML onClick attribute. The value of this attribute may be any number of JavaScript statements, separated by semicolons, which are executed when the user clicks on the Checkbox.
<INPUT type="checkbox" a definition of the handler onClick="handler-statements"> checkbox.onclick a reference to the handler checkbox.onclick(); an explicit invocation of the handler
A Checkbox object is created with a standard HTML <input> tag, with the addition of the new onClick attribute. Multiple Checkbox objects are often created in groups by specifying multiple <input> tags which have the same name attribute.
<form> ... <input type="checkbox" specifies that this is a checkbox [ name="name" ] a name that can later be used to refer to this checkbox or to the group of checkboxes with this name; specifies the name property [ value="value" ] the value returned when this checkbox is selected; specifies the value property [ checked ] specifies that the checkbox is initially checked Specifies the defaultChecked property [ onClick="handler" ] JavaScript statements to be executed when the Checkbox is clicked > label the HTML text that should appear next to the Checkbox ... </form>
With no arguments, the Date() method creates a Date object set to the current date and time. Otherwise, the arguments to Date() specify the date, and, optionally, the time, for the new object. The Date object is built into JavaScript and does not have an HTML analog. Most of the Date object methods are invoked through an instance of the Date object. For example:
d = new Date(); //get today's date and time system.write('Today is: " + d.toLocaleString()); //and print it out
This syntax for creating Date objects assumes that date and time values are specified in local time. When your code must work the same way regardless of the time zone in which it is run, you should specify all your hard-coded dates in the GMT (or UTC) time zone. The most common use of the Data object is to subtract the millisecond representations of the current time from some other time to determine the difference.
Buggy to the point of uselessness in Netscape 2.0. See also Date.parse, Date.UTC(). (Note that the Date.parse() and Date.UTC() functions, though related to Date, do not operate on the Date object.)
To create a Date object, use one of the following five syntaxes. In the third through fifth syntaxes, the specified times are interpreted as local (not GMT) times.
new Date(); new Date(milliseconds) milliseconds between date and 12AM 1/1/70 new Date(date_string); date_string = month_name dd, yy [hh:mm[:ss]] new Date(year, month, day); year minus 1900; month 0-11; day 1-31 new Date(year, month, day, hours, minutes, seconds) 24-hour clock
Returns the day of the month of a Date object. Return values are between 1 and 31.
Returns the day of the week of a Date object. Return values are between 0 (Sunday) and 6 (Saturday).
Returns the hours field of a Date object. Return values are between 0 (midnight) and 23 (11 PM).
Returns the minutes field of a Date object. Return values are between 0 and 59.
Returns the month field of a Date object. Return values are between 0 (January) and 11 (December).
Returns the seconds field of a Date object. Return values are between 0 and 59.
Returns the internal, millisecond representation of a Date object (i.e., the number of milliseconds between midnight GMT on 1/1/1970 and the specified date).
Returns the difference in minutes between this date (in the local time zone) and GMT. Tells you what time zone the JavaScript code is running in. Since getTimezoneOffset is invoked through a Date object, but doesn't reference the Date object, it should actually be its own function.
Returns the year field of a Date object. Return value is the year minus 1900 (e.g., 96 for 1996).
Parses a string representation of a date and returns it in millisecond format.
Sets the day of the month field of a Date object.
date.setDate(day_of_month) // day_of_month is 1-31
Sets the hour field of a Date object.
date.setHours(hours) //hours is integer betw 0 (midnight) and 23 (11pm)
Sets the minutes field of a Date object.
date.setMinutes(minutes) //minutes is integer betw 0 and 59
Sets the month field of a Date object.
date.setMonth(month) //month is integer betw 0 (Jan) and 11 (Dec)
Sets the seconds field of a Date object.
date.setSeconds(seconds) //seconds is integer betw 0 and 59
Sets a Date object in the milliseconds between the desired date/time and midnight GMT on January 1, 1970. Representing a date in this millisecond format makes it independent of time zone.
date.setTime(milliseconds)
Sets the year field of a Date object.
date.setYear(year) // year is year minus 1900; e.g. 96 for 1996
Converts a Date to a string, using the GMT time zone; format of string varies slightly according to platform.
Converts a Date to a string, using the local time zone; uses local conventions for data and time formatting.
Converts a numeric date and time specification to millisecond format.
Date.parse() is a function that is related to the Date object, but it is not a method of (or invoked on) the Date object. Date.parse() parses a date/time string and returns the number of milliseconds between the specified date/time and midnight, January 1st, 1970, GMT. This number can be used directly, used to create a new Date object, or to set the date in an existing Date object with Date.setTime().
Date.parse() understands the IETF standard date format used in email and other Internet communications (e.g., Wed, 8 May 1996 17:41:46 -0400), as well as partial dates of this format; it also understands the GMT time zone, and the standard abbreviations for the time zones of the U.S. Buggy in Netscape 2.0. See also Date, Date.UTC().
date.parse(date_string)
Date.UTC() is a function that is related to the Date object, but is not a method of the Date object or invoked on it; it is always invoked as Date.UTC(), not as date.UTC(), on some object date.
Date.UTC converts time in UTC (Universal Coordinated Time) format (i.e., in the GMT zone) to milliseconds. It returns the number of milliseconds between midnight on January 1st, 1970, UTC and the time specified by the arguments. This can be used by the Date() constructor method and by the Date.setTime() method.
For arguments, use: year minus 1900 (e.g., 96 for 1996); month 0 (January) through 11 (December); 24-hour clock for hour (0-23). In Netscape 2.0, Date.UTC() does not compute the correct number of milliseconds. See also Date, Date.parse.
date.UTC(year, month, day, [, hours [, minutes [, seconds ]]]);
To create a Date object using a UTC time specification, you can use code like this:
d = new Date(Date.UTC(96, 4, 8, 16, 30));
The currently displayed HTML document. An instance of the Document object is stored in the document field of the Window object. As a special case, when referring to the Document object of the current window (i.e., the window in which the JavaScript code is executing), you can omit the window reference and simply use document. Available in Netscape 2.0. See also Form, Frame, Window.
window.document document // To refer to Document obj of current window
Note that for all attributes to set a color, the value can be one of the standard color names recognized by JavaScript, or an RGB value in six hexadecimal digits (RRGGBB).
String that specifies the color of activated links (i.e., links being selected by user). Can be set directly in the document <head>, or inherited from the alink attribute in the <body>.
An array of Anchor objects, one for each anchor (i.e., hypertext target) in the document.
Read-only integer specifying the number of elements in the anchors[] array.
An array of Java objects, one for each <applet> that appears in the document.
A read-only integer specifying the number of elements in the applets[] array.
String that specifies the background color of the document. Can be set directly at any point in document, or inherited from the bgcolor attribute in the <body>. Buggy in Netscape 2.0.
A string that is the value of a cookie associated with this document. String property that allows you to read, create, modify, and delete the cookie(s) that apply to the current document. A "cookie" is a small amount of named data stored by the Web browser so that it can use data input on one page in another page, or recall user preferences across Web-browsing sessions.
document.cookie
The read and write values of the cookie property generally differ. In a JavaScript expression, the cookie property returns a string containing all the cookies from the current document, in name=value pairs (separated by semicolons). Use String.indexOf() and String.substring() to determine the value of a particular cookie. Since cookies cannot contain any semicolons, commas, or whitespace, they are commonly encoded using escape() before storing and decoded using unescape() after retrieving.
To associate a cookie value with the current document for the current Web browsing session, set document.cookie to a string of the form name=value. To create a cookie that can last across browser sessions, include an expiration date by setting document.cookie to a string of the form:
name=value; expires=date
date should be a date specification in the format written by Date.toGMTString().
String that specifies the Internet domain which the document is from; used for security purposes.
An array of Java objects, one for each <embed> tag that appears in the document.
Read-only integer that specifies the number of elements in the embeds[] array.
String that specifies the default color of document text. Can be set directly in the document <head>, or inherited from the text attribute in the <body>.
An array of Form objects, one for each <form> that appears in the document.
Read-only integer specifying the number of elements in the forms[] array.
An array of Image objects, one for each image embedded in the document with the <img> tag.
The number of elements in the images[] array.
Read-only string that contains the (local) date and time at which document was most recently modified (derived from the HTTP header).
String that specifies the color of unvisited links. Can be set directly in the document <head>, or inherited from the link attribute in the <body>.
An array of Link objects, one for each hypertext link in the document.
Read-only integer specifying the number of elements in the links[] array.
Synonym for the URL property. Use URL instead because it is less likely to be confused with the Window.location property.
Synonym for the embeds[] array.
The number of elements in the plugins[] or embeds[] array.
Read-only string that contains the URL of the document from which the current document was reached.
Read-only string that specifies the <title> of the document.
Read-only string that specifies the URL of the document that contained the link that referred to the current document.
String that specifies the color of visited links. Can be set directly in the document <head>, or inherited from the vlink attribute in the <body>.
Clears the window or frame that contains document.
Displays any output to document that has been written but not yet displayed, and closes the output stream.
Opens a stream to document, so that subsequent document.write() calls can append data to the document.
Appends each of its arguments, in order, to document. Numeric values are converted to a string representation; boolean values are appended as either "true" or "false." When invoked in scripts that are run while the document is loading, you can call document.write() to insert dynamically generated HTML text into the document.
document.write(value,...)
When invoked within a <script> tag on an HTML document that is being parsed, arguments are appended at the location of the tag; when invoked on a document that is not being parsed, the document must first be opened with Document.open().
Identical to write(), except that it appends a newline character to the output.
The following event handlers are, strictly speaking, properties of Window, not Document:
Invoked when the document is fully loaded. Specified by the onLoad attribute of <body>.
Invoked when the document is unloaded. Specified by the onUnload attribute of <body>.
The Document object obtains values for a number of its properties from attributes of the HTML <body> tag. Further, the HTML contents of a document appear within the <body> and </body> tags.
<body [ BACKGROUND="imageURL" ] a background image for the document [ BGCOLOR="color" ] a background color for the document [ text="color" ] the foreground color of the document's text [ LINK="color" ] the color for unvisited links [ alink="color" ] the color for activated links [ VLINK="color" ] the color for visited links [ onLoad="handler" ] JavaScript to run when the document is loaded [ onUnload="handler" ] JavaScript to run when the document is unloaded > HTML document contents go here </body>
Technically speaking, there is no single Element object in JavaScript. Each of the various types of form elements are types of Element objects. Available in Netscape 2.0. See also Button, Checkbox, FileUpload, Form, Hidden, Password, Radio, Reset, Select, Submit, Text, Textarea.
form.elements[i] form.name
Read-only reference to Form object that contains this element.
Read-only string (from the HTML name attribute) that specifies the name of this element. The name of a form element is used for two purposes. First, it is used when the form is submitted. Data for each element in the form is usually submitted in the format:
name=value // name and value are encoded as necessary for transmission
If a name is not specified for a form element, then the data for that element cannot be meaningfully submitted to a Web server. The second use of the name property is to refer to a form element in JavaScript code.
Read-only string property (Netscape 3.0 and later) that specifies the type of the form element. The value depends on the input element:
Object Type | HTML Tag | type Property |
---|---|---|
Button | <input type=button> | "button" |
Checkbox | <input type=checkbox> | "checkbox" |
FileUpload | <input type=file> | "file" |
Hidden | <input type=hidden> | "hidden" |
Password | <input type=password> | "password" |
Radio | <input type=radio> | "radio" |
Reset | <input type=reset> | "reset" |
Select | <select> | "select-one" |
Select | <select multiple> | "select-multiple" |
Submit | <input type=submit> | "submit" |
Text | <input type=text> | "text" |
Textarea | <textarea> | "textarea" |
Read/write string property that specifies the value to be sent to the server for this element when the form is submitted; initial value specified by the HTML value attribute. For Button, Submit, and Reset objects, the value property specifies the text to appear within the button.
The built-in escape() function creates and returns a new string that contains an encoded version of s to allow transmission of data. A common use of escape() is to encode cookie values, which have restrictions on the punctuation characters they may contain. Available in Netscape 2.0. See also String, unescape().
escape(s) s is the string to be "escaped" or encoded
All spaces, punctuation, and accented characters are converted to the form %xx, where xx is two hexadecimal digits that represent the ISO-8859-1 (Latin-1) encoding of the character. For example:
escape("Hello World!");
yields the string:
Hello%20World%21
A built-in JavaScript function; not a method of any object. Executes the code in its string argument code, which may contain one or more JavaScript statements (separated by semicolons). You can also use eval() to evaluate a JavaScript expression rather than execute a statement. Returns the value of the last expression in code that it evaluates. eval() allows a JavaScript program to dynamically modify the code that it executes.
Crashes Netscape 2.0 on 16-bit Windows (version 3.1) platforms. A possible workaround: use Window.setTimeout() with a zero-millisecond delay. In 3.0, eval has become a method of the Object object. See also Object, Window.
eval(code)
Represents a file upload input element in a form. It looks like a text input field, with the addition of a Browse... button that opens a directory browser. Entering a filename into a FileUpload object (either directly or through the browser) causes Netscape to submit the contents of that file along with the form (which must use "multipart/form-data" encoding and the post method). The FileUpload object does not recognize the HTML value attribute to specify an initial value for the input field. For security reasons, only the user may enter a filename; JavaScript may not enter text into the FileUpload field in any way. Available in Netscape 2.0; enhanced in 3.0. See also Element, Form, Text.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the FileUpload object.
Read-only string, set by the HTML name attribute, that specifies the name of the FileUpload object. This name can also be used to reference the FileUpload object as a property of its form. (For example, if the name property of a FileUpload object in form foo is "info," then foo.info refers to the FileUpload object.)
Read-only string that specifies the type of this form element. For FileUpload objects, it has the value "file." Available in Netscape 3.0 and later.
Read-only string that specifies the value contained in the input field (which is also the value sent to the server when the form is submitted). In Netscape 2.0, this field is always blank. In 3.0 any filename specified by the user may be read, but the property still may not be set.
Removes the keyboard focus from the FileUpload object. Until focus is granted to some other form element, the user's keystrokes may be ignored by all elements. Due to a bug in Netscape 2.0, the blur() method invokes the onblur() event handler.
Sets the keyboard focus to the FileUpload object. When focus is set, all keystrokes are automatically entered into this object.
Defined by the HTML onBlur attribute, the value of which may be any number of JavaScript statements, separated by semicolons; these statements are executed whenever the FileUpload object loses keyboard focus because of a user action. onblur should only be invoked by direct user actions, but a bug in Netscape 2.0 causes it to be invoked by the FileUpload.blur() method.
Invoked when the user changes the value in the FileUpload object and moves the keyboard focus elsewhere. This event handler is not invoked for every keystroke in the FileUpload object, but only when the user completes an edit.
Invoked when a user action causes the FileUpload object to gain the keyboard focus.
A FileUpload object is created with a standard HTML <input> tag, with the addition of optional attributes for event-handlers:
<form ENCtype="multipart/form-data" method=post> required attributes ... <input type="file" specifies that this is a FileUpload object [ name="name" ] a name that can later be used to refer to this object specifies the name property [ size=integer ] how many characters wide the object is [ maxlength=integer ] max allowed number of input characters [ onBlur="handler" ] the onblur() event handler [ onChange="handler" ] the onchange() event handler [ onFocus="handler" ] the onfocus() event handler ...
Represents an HTML <form> in a document. Each form in a document is represented as an element of the Document.forms[] array. Named forms are also represented by the form_name property of their document, where form_name is the name specified in the name attribute of the <form> tag. Available in Netscape 2.0. See also Button, Checkbox, Element, FileUpload, Hidden, Password, Radio, Reset, Select, Submit, Text, Textarea.
document.form_name document.forms[form_number] document.forms.length
The elements of a form (buttons, input fields, check boxes, and so on) are collected in the Form.elements[] array. Named elements, like named forms, can also be referenced directly by name--the element name is used as a property name of the Form object. Thus, to refer to a Text object element named "phone" within a form named "questionnaire," you might use the JavaScript expression:
document.questionnaire.phone
Read/write string specifying the URL to which the form is to be submitted. Initially specified by the action attribute of the <form> HTML tag.
An array of input elements that appear in the form. Each element is a Button, Checkbox, Hidden, Password, Radio, Reset, Select, Submit, Text or Textarea object.
The number of items in the elements[] array.
Read/write string that specifies the encoding method used for form data. Initially specified by the enctype attribute of the <form> HTML tag. The default encoding of "application/x-www-form-urlencoded" is almost always appropriate.
Read/write string that specifies the technique for submitting the form. It should have the value "get" or "post". Initially specified by the method attribute.
Read/write string that specifies the name of the frame or window in which the results of submitting a form should be displayed. Initially specified by the target attribute. The special names "_top", "_parent", "_self", and "_blank" are also supported for the target property and the target attribute.
Resets each of the input elements of the form to their default values.
Method that submits a form.
Invoked just before the elements of the form are reset. Specified by the onReset attribute.
Invoked just before the form is submitted. Specified by the onSubmit attribute of the <form> tag. This event handler allows form entries to be validated before being submitted.
A Form object is created with a standard HTML <form> tag. JavaScript adds the optional onSubmit event handler attribute to this tag. The form contains any input elements created with the <input> tag between <form> and </form>.
<form [ name="form_name" ] to name the form in JavaScript [ target="window_name" ] the name of the window for responses [ action="url" ] the URL to which the form is submitted [ method=(get|post) ] the method of form submission [ enctype="encoding" ] how the form data is encoded [ onSubmit="handler" ] a handler invoked when form is submitted > form text and <input> tags go here </form>
Though the Frame object is sometimes referred to, there is, strictly speaking, no such object. All frames within a browser window are instances of the Window object, and they contain the same properties and support the same methods, and event handlers as the Window object does. See the Window object, and its properties, methods, and event handlers for details.
Note, however, that there are a few practical differences between Window objects that represent top-level browser windows and those that represent frames within a browser window:
Available in Netscape 2.0.
window.frames[i] window.frames.length frames[i] frames.length
An object wrapper around the basic function data type; this object type exists so that functions can have properties and methods associated with them. When a function value is used in an "object context," i.e., when you attempt to invoke a method or read a property of a function, JavaScript internally converts the function value into a temporary Function object, so that the method can be invoked or the property value read.
function functionname(argname1 [, . . . argname_n)] { body // body of function }
To create a new function, use the Function() constructor method:
new Function([argname1 [, ..., argname_n]], body)
Functions defined in this way are sometimes called "anonymous" because they are not given a name when they are created. Just as JavaScript converts from a function value to a Function object whenever necessary, so it will convert from a Function object (created with the Function() constructor) to a function value whenever you use the object in a function value context--i.e., whenever you invoke it with the () operator. This conversion from Function object to function value is done by the valueOf() method.
Since there is no special keyword in JavaScript that refers to the Function object of the currently executing function, you must refer to Function objects by name, as in:
function myfunc() { if (myfunc.arguments.length == 0) return; ... }
Enhanced in Netscape 3.0. See also the Object Object.
An array of arguments that were passed to the function. Can only be accessed from within the body of a function. Note that the arguments[] property is actually just a reference to the Function object itself. Thus, instead of using function.arguments[i] and function.arguments.length, you can use function[i] and function.length.
The number of elements in the arguments[] array.
A reference to the Function object that invoked this one, or null if the function is invoked at the top level. Can only be accessed from within the body of a function. You can print out the caller for debugging purposes, and you can even invoke that function through the caller property.
An object which, for constructor functions, defines properties and methods that will be shared by all objects created with that constructor function. Any objects created through a constructor function will "inherit" the properties and methods defined in that prototype.
Converts the Function object to a string by returning the function definition (a string of valid JavaScript code).
Returns the function value contained in a Function object. See the Object.valueOf() method.
A function that takes a JavaObject object and returns the JavaClass object of that JavaObject. Available in Netscape 3.0. See also JavaArray, JavaClass, JavaObject, JavaPackage, and Packages.
getClass(javaobj)
Don't confuse the JavaScript getClass() function with the getClass method of all Java objects. Similarly, don't confuse the JavaScript JavaClass object with the Java java.lang.Class class.
Consider the Java rectangle object created with the following line:
var r = new java.awt.Rectangle();
r is a JavaScript variable that holds a JavaObject object. Calling the JavaScript function getClass() returns a JavaClass object that represents the java.awt.Rectangle class:
var c = getClass(r);
You can see that this is so by comparing this JavaClass object to java.awt.Rectangle:
if (c == java.awt.Rectangle) ...
The Java getClass() method is invoked differently and performs an entirely different function:
c = r.getClass();
After executing the above line of code, c is a JavaObject that represents a java.lang.Class object. This java.lang.Class object is a Java object that is a Java representation of the java.awt.Rectangle class. See your Java documentation for details on what you can do with the java.lang.Class class.
To summarize, you can see that the following expression will always evaluate to true for any JavaObject o:
(getClass(o.getClass()) == java.lang.Class)
An invisible form element that allows arbitrary data to be transmitted to the server when the form is submitted. You can use a Hidden object when you want to transmit additional information, besides the user's input data, to the server. (Cookies can also be used to transmit data from client-to-server; however, cookies are persistent on the client side.)
When an HTML document is generated on the fly by a server, another use of Hidden form elements is to transmit data from the server to the client for later processing by JavaScript on the user's side.
Hidden objects can also be useful for communication between CGI scripts, even without the intervention of JavaScript on the client side. In this usage, one CGI script generates a dynamic HTML page containing hidden data, which is then submitted back to a second CGI script. This hidden data can communicate state information, such as the results of submission of a previous form. Enhanced in Netscape 3.0. See also Element, Form, Document.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the Hidden object.
Read-only string, set by the HTML name attribute, that specifies the name of the Hidden object. This is also the name that can be used to reference the Hidden object as a property of its form.
Read-only string that specifies the type of this form element. For Hidden objects, it has the value "hidden." Available in Netscape 3.0 and later.
Read/write string, initially set by the HTML value attribute, which specifies arbitrary data to be transmitted to the server when the form is submitted. This data is never visible to the user.
A Hidden object is created with a standard HTML <input> tag:
<form> ... <input type="hidden" specifies that this is a Hidden object [ name="name" ] a name that can later be used to refer to this object; specifies the name property [ value="value" ] the value transmitted when the form is submitted; specifies the initial value of the value property > ... </form>
Read-only array of strings that specify the URLs that have been previously visited by the browser. The contents of this list are equivalent to the URLs listed in Netscape's Go menu. You can use the History object to implement your own Forward and Back buttons, or other navigation controls, within a window.
In Netscape 2.0, and in 3.0 without data tainting, JavaScript can use the length property to determine the number of entries on the History object's URL list, and can use the back(), forward(), and go() methods to cause the browser to revisit any of the URLs on the list, but it cannot directly or indirectly read the URLs stored in the array.
In 3.0 and later, when the data tainting security model is enabled, the elements of the array are available and may be read (but not changed). Additional properties (described below) are also available. See also Location.
window.history frame.history history
Read-only string that specifies the URL of the current document. Only available with data tainting enabled in Netscape 3.0.
The number of URLs that are saved in the History object. (Note that the History object does not provide a property that specifies the position of the current URL in the history list, and because there is no method to move to an absolute position in the history list, only methods to move relative to the current position.)
Read-only string that specifies the URL of the document after this one in the history list. Only available with data tainting enabled in Netscape 3.0.
Read-only string that specifies the URL of the document before this one in the history list. Only available with data tainting enabled in Netscape 3.0.
Go backwards to a previously visited URL (if any). Calling this method has the same effect as a user's click on the Netscape Back button; it's also equivalent to:
history.go(-1);
Go forward to a previously visited URL (if any). Calling this method has the same effect as a user's click on the Netscape Forward button; it's also equivalent to:
history.go(1);
Go to a previously visited URL (if any).
history.go(relative_position); history.go(target_string); //* buggy in 2.0 */
The first form of the History.go() method takes an integer argument (positive argument=forward; negative argument=back) and causes the browser to visit the URL that is the specified number of positions distant in the history list maintained by the History object. Thus history.go(-1) is equivalent to history.back() (and produces the same effect as a user click on the Netscape Back button). Similarly, history.go(3) is equivalent to calling history.forward() three times. In the second syntax, the target_string argument is supposed to make the browser revisit the first (i.e., most recent) URL that contains the specified string. Caveat: This form of the method is buggy in Netscape 2.0 and may cause the browser to crash.
Returns a string of HTML text. When this string is formatted by a browser (i.e., written with document.write()) it displays the browser history as a table of URLs, each with an appropriate hyperlink. Only available with data tainting enabled in Netscape 3.0.
The Image objects in the document.images[] array represent the images embedded in an HTML document using the <img> tag. Only two properties are writeable: src and lowsrc. When you set src, the browser will load the image specified by the new value of the src property, or by the lowsrc property, for low-resolution monitors. (Note that lowsrc must be set before src because the latter starts the download of the new image.) Setting src can be used to change the graphics on a page in response to user actions (e.g., changing the image on a button to indicate that it is or is not available for selection based on whether the user has input certain information).
Available in Netscape 3.0. (Note that because of a bug in Netscape 2.0, all images in a page that contains JavaScript must have width and height attributes specified, even though the Image object is not available in 2.0.) See also Document.
document.images[i] document.images.length document.image-name
You can dynamically create Image objects using the Image() constructor method:
new Image([width, height]);
Read-only integer that specifies the width, in pixels, of the border around an image. Its value is set by the border attribute.
Read-only boolean that specifies whether the image is completely loaded yet; if an error occurs or the loading is aborted, the complete property will be set to true.
Read-only integer that specifies the height, in pixels, of the image. Its value is set by the height attribute.
Read-only integer that specifies the amount of extra horizontal space, in pixels, inserted on the left and right of the image. Its value is set by the hspace attribute.
Read/write string that specifies the URL of an alternate image, suitable for display at low resolutions. Its initial value is set by the lowsrc attribute. Setting this property has no immediate effect; however, if src is set, a new image will be loaded, and on low-resolution systems, the current value of lowsrc will be used instead of the newly updated value of src.
Read-only string, specified by the HTML name attribute, that gives the name of the image. When an image is given a name with the name attribute, a reference to the image is placed in the image-name property in addition to the document.images[] array. Image objects created with the Image() constructor function do not have names, and cannot have names assigned.
Read/write string that specifies the URL of the image to be displayed. Its initial value is set by the src attribute.
Read-only integer that specifies the amount of extra vertical space, in pixels, inserted above and below the image. Its value is set by the vspace attribute.
Read-only integer that specifies the width, in pixels, of the image. Its value is set by the width attribute.
Invoked if the user aborts the download of an image. Defined by the onAbort attribute, the value of which may be any number of JavaScript statements (separated by semicolons) that will be executed when the user aborts loading.
<img src="url onAbort="handler a definition of the handler ...> image.onabort a reference to the handler image.onabort() an explicit invocation of the handler
Invoked if an error occurs while downloading the image. Defined by the onError attribute, the value of which may be any number of JavaScript statements (separated by semicolons) that will be executed when an error occurs during loading.
<img src="url onError="handler a definition of the handler ...> image.onerror a reference to the handler image.onerror() an explicit invocation of the handler
Invoked when the image successfully finishes loading. Defined by the onLoad attribute, the value of which may be any number of JavaScript statements (separated by semicolons) that will be executed when the image is completely loaded.
<img src="url onLoad="handler a definition of the handler ...> image.onload a reference to the handler image.onload() an explicit invocation of the handler
The Image object is created with a standard HTML <img> tag, with the addition of event handlers. Some <img> attributes have been omitted from the syntax below, because they are not used by or accessible from JavaScript.
<img src="url" the image to display width=pixels the width of the image height=pixels the height of the image [ name="image-name" ] a property name for the image [ lowsrc="url" ] alternate low-resolution image [ border=pixels ] width of image border [ hspace=pixels ] extra horizontal space around image [ vspace=pixels ] extra vertical space around image [ onLoad=handler ] invoked when image is fully loaded [ onError=handler ] invoked if error in loading [ onAbort=handler ] invoked if user aborts load >
Tests whether an argument (x) is "not a number"; specifically determines whether it is the reserved value NaN, which represents an illegal number (such as the result of dividing zero by zero). This function is required because it is not possible to express the NaN value as a literal in JavaScript. Commonly used to test the results of parseFloat() and parseInt() to see if they represent legal numbers, or to check for arithmetic errors, such as division by zero. Not implemented on all platforms for Netscape 2.0. See also parseFloat, parseInt.
isNaN(x)
A representation of a Java array, which allows JavaScript to read and write the elements of the array using familiar JavaScript array syntax. When reading and writing values from array elements, data conversion between JavaScript and Java representations is handled by the system. Note that Java arrays differ from JavaScript arrays in the following ways. First, Java arrays have a fixed length that is specified when they are created; thus, the JavaArray length field is read-only. Second, Java arrays are typed (i.e., their elements must all be of the same data type); attempting to set an array element to a value of the wrong type will result in a JavaScript error. Available in Netscape 3.0. See also getClass, JavaClass, JavaObject, JavaPackage, Packages.
javaarray.length the length of the array javaarray[index] read or write an array element
Read-only integer that specifies the number of elements in the Java array represented by the JavaArray object.
If java.awt.Polygon is a JavaClass object, you can create a JavaObject representing an instance of the class using:
p = new java.awt.Polygon();
This object p has properties xpoints and ypoints, which are JavaArray objects representing Java arrays of integers. You could initialize the contents of these arrays with JavaScript code like the following:
for(int i = 0; i < p.xpoints.length; i++) p.xpoints[i] = Math.round(Math.random()*100); for(int i = 0; i < p.ypoints.length; i++) p.ypoints[i] = Math.round(Math.random()*100);
JavaScript representation of a Java class. Its properties represent the public static fields and methods (also called class fields and methods) of the represented class; these properties can be used to read and write the static fields and to invoke the static methods of Java classes. Use a for/in loop to enumerate the properties for any given class.
Note that the JavaClass object does not have properties representing the instance fields of a Java class, which are represented by the JavaObject object. However, the JavaClass object does allow for the creation of Java objects (represented by a JavaObject object) using the new keyword and invoking the constructor method of a JavaClass. For primitive data types, conversion between JavaScript values and Java values is handled automatically by the system. Note that Java is a typed language (i.e., each of the fields of an object must adhere to a specific data type). Available in Netscape 3.0. See also getClass, JavaArray, JavaObject, JavaPackage, Packages.
javaclass.static_field read or write a static Java field javaclass.static_method(...) invoke a static method new javaclass(...) create a new Java object
java.lang.System is a JavaClass object that represents the java.lang.System class in Java. The following code reads a static field of this class:
var java_console = java.lang.System.out;
Invoke a static method of this class with a line such as:
var version = java.lang.System.getProperty("java.version");
The JavaClass object allows you to create a new Java object like this:
var java_date = new java.lang.Date();
JavaScript representation of a Java object. Its properties represent the public instance fields and methods defined for the Java object; these properties can be used to read and write the public instance fields and to invoke the public instance methods of a Java object. (The static/class fields and methods are represented by the JavaClass object.) Use the for/in loop to enumerate the properties of any given JavaObject.
For primitive data types, conversion between JavaScript values and Java values is handled automatically by the system. Note that Java is a typed language (i.e., each of the fields of an object must adhere to a specific data type). Available in Netscape 3.0. See also getClass, JavaArray, JavaClass, JavaPackage, Packages.
javaobject.field read or write an instance field javaobject.method(...) invoke an instance method
java.lang is the name of a JavaPackage that contains the JavaClass java.lang.System. This class has the property out, which is a JavaObject. This JavaObject has a property println, which is a method that can be invoked like this:
java.lang.System.out.println("Hello from Java!");
The previous line of code will write a message on the Java console. java.awt.Rectangle is a JavaClass that represents the java.awt.Rectangle class. The following line creates a JavaObject that represents an instance of this class:
var r = new java.awt.Rectangle(0,0,4,5);
Then access the public fields of this JavaObject r using code such as:
var perimeter = 2*r.width + 2*r.height;
A JavaScript representation of a Java package. A package in Java is a collection of related classes. In JavaScript, a JavaPackage can contain classes (represented by the JavaClass object) and it can also contain other JavaPackage objects.
The property naming scheme for the JavaPackage hierarchy mirrors the naming scheme for Java packages. However, the JavaPackage object named java does not actually represent a package in Java, but is simply a convenient placeholder for other JavaPackages that do represent java.lang, javat, java.io, and other important Java classes. Think of the JavaPackage object as representing a Java package representing a directory in the Java class hierarchy.
The java JavaPackage object is actually a property of every Window object, which makes it a "global" variable in client-side JavaScript. Since every JavaScript expression is evaluated in the context of one window or another, you can always just use java and know that you will be referring to the JavaPackage object you want. There are other global JavaPackage objects as well (sun, netscape). The Packages property is a JavaPackage object that contains references to each of these java, sun, and netscape JavaPackages.
Available in Netscape 3.0. See also JavaArray, JavaClass, JavaObject, Packages.
package.package_name refers to another JavaPackage package.class_name refers to a JavaClass object
The properties of a JavaPackage object are the names of the JavaPackage objects and JavaClass objects that it contains. These properties will be different for each individual JavaPackage. Note that it is not possible to use the JavaScript for/in loop to iterate over the list of property names of a Package object; consult a Java reference manual, or examine the Java class hierarchy, to determine the packages and classes contained within any given package.
You can use JavaPackage objects to refer to any Java class. The java.lang.System class, for example, is:
java.lang.System
Or:
Packages.java.lang.System
Similarly, the netscape.javascript.JSObject class is:
Packagestscape.javascript.JSObject
Represents a hypertext link or a clickable area of a client-side image map in an HTML document. A subclass of the Location object; however, Link differs in that it does not load a new URL automatically (i.e., it changes the URL that the link refers to, but the URL is not displayed until the user selects it). Note that in JavaScript, a hypertext link is a Link object, and a named link destination is an Anchor object. Enhanced in Netscape 3.0. See also Anchor, Location.
document.links[] document.links.length
The hash portion of the HREF URL, including the leading hash (#) mark. This portion specifies the name of an anchor within the object referred to by the URL.
The combination of the hostname and port portions of the HREF URL.
The hostname portion of the HREF URL.
The complete URL specified by the HREF property.
The path portion of the HREF URL.
The port portion of the HREF URL.
The protocol portion of the HREF URL, including the trailing colon.
The search or query portion of the HREF URL, including the leading question mark.
The name of a Window object (i.e., a frame or a toplevel browser window) in which the HREF URL should be displayed.
The values of the following attributes may be any number of JavaScript statements separated by semicolons.
Statements invoked when the user clicks on the link. Defined by the onClick attribute of the HTML <a> or <area> tag that defines the hypertext link. The onclick() event handler is invoked before the browser follows the clicked hypertext link.
<a onClick="handler-statements"> a definition of the handler link.onclick a reference to the handler link.onclick(); an explicit invocation of the handler
Statements invoked when the user moves the mouse off of the link. Defined by the onMouseOut attribute of the HTML <a> or <area> tag that defines the hypertext link. Available in 3.0 and later.
<a onMouseOut="handler-statements"> a definition of the handler <area onMouseOut="handler-statements"> another definition link.onmouseout a reference to the handler link.onmouseout(); an explicit invocation of the handler
Statements invoked when the user moves the mouse over the link. The status property of the current window may be set here. Defined by the onMouseOver attribute of the HTML <A> or <area> tag that defines the hypertext link.
<a onMouseOver="handler-statements"> a definition of the handler <area onMouseOver="handler-statements"> another definition link.onmouseover a reference to the handler link.onmouseover(); an explicit invocation of the handler
A Link object is created with standard <a> and </a> tags, with the addition of the onClick, onMouseOver, and onMouseOut event-handler attributes. The HREF attribute is required for all Link objects. If the name attribute is also specified, then an Anchor object is also created:
<A HREF="url" [ name="anchor_tag" ] creates an Anchor object [ target="window_name" ] where the HREF should be displayed [ onClick="handler" ] invoked when link is clicked [ onMouseOver="handler" ] invoked when mouse is over link [ onMouseOut="handler" ] invoked when mouse leaves link > link text or image the visible part of the link </A>
In Netscape 3.0 and later, a Link object is also created by each <area> tag within a client-side image map; standard HTML with the addition of event-handler tags:
<MAP name="map_name"> <area SHAPE="area_shape" COORDS=coordinates HREF="url" [ target="window_name" ] where the HREF should be displayed [ onClick="handler" ] invoked when area is clicked [ onMouseOut="handler" ] invoked when mouse leaves area > . . . </MAP>
Represents a URL. Each of the properties of the Location object is a read/write string that contains one or more portions of the URL described by the object. The location property of Window object is a Location object that specifies the URL of the document. Changing properties of a Location object of a Window causes the browser to read in the changed URL. To load a new URL, you usually set the location property to a string; or you can set any of the properties of the Location object instead. The href property is commonly used. If you just set the hash property of the window.location object, the browser will jump to the newly specified anchor.
When you set the location or location.href properties to a URL that you have already visited, the browser will either load that URL from the cache, or will check with the server to see if the document has changed and reload it if necessary. In Netscape 2.0, it will always check with the Web server. In 3.0, the action it takes depends on the Verify Document setting in Netscape's Network Preferences.
See also Document, Link, Window.
location window.location document.links[]
The fields of a Location object refer to the various portions of a URL, which has the following general format:
protocol://hostname:port/pathname?search#hash
The hash portion of the URL, including the leading hash mark (#). This portion specifies the name of an anchor within a single HTML file.
location.hash window.location.hash document.links[i].hash
A combination of the hostname and port portions of the URL.
location.host window.location.host document.links[i].host
The hostname portion of the URL.
location.hostname window.location.hostname document.links[i].hostname
The complete URL.
location.href window.location.href document.links[i].href
The path portion of the URL.
location.pathname window.location.pathname document.links[i].pathname
The port portion of the URL.
location.port window.location.port document.links[i].port
The protocol portion of the URL, including the trailing colon.
location.protocol window.location.protocol document.links[i].protocol
The search or query portion of the URL, including the leading question mark.
location.search window.location.search document.links[i].search
Reloads the current document from the cache or server. The optional force argument is a boolean that specifies whether the document should be reloaded even if it hasn't been modified; if omitted or false, the method will reload the full page only if it has been changed since it was last loaded.
location.reload() location.reload(force)
Replaces the current document with a new one, without generating a new entry in the browser's session history.
location.replace(url)
Read-only reference to a placeholder object that contains mathematical functions and constants. Math is itself an object, not a class of objects, so its constants and methods are invoked directly through it. Math is actually a global property of the Window object, and as such, is usually referred to as Math, rather than as window.Math. random() function added in 3.0. See also Number.
Math.constant Math.function()
Invoke functions and constants as follows:
y = Math.sin(x); area = radius * radius * Math.PI;
The constant $e$ (the base of natural logarithms) The natural logarithm of 10 The natural logarithm of 2 The base-10 logarithm of $e$ The base-2 logarithm of $e$ The constant pi The reciprocal of the square-root of 2 The square-root of 2
Computes an absolute value.
Math.abs(x) // x is any numeric value or expression
Computes an arc cosine (inverse cosine). Return value is between 0 and pi radians.
Math.acos(x) // x is a numeric value or expression between -1.0 and 1.0 radians
Computes an arc sine (inverse sine). The return value is between -pi/2 and pi/2 radians.
Math.asin(x) // x is a numeric value or expression between -1.0 and 1.0 radians
Computes an arc tangent (inverse tangent) in radians. The return value is between -pi/2 and pi/2 radians.
Math.atan(x) //x is any numeric value or expression
Computes the counter-clockwise angle from the positive X axis to a point (x, y). Performs half of the conversion between Cartesian coordinates and polar coordinates; computes and returns the angle theta of an (x, y) point.
Math.atan2(x, y) // x, y are the coordinates of the point
Rounds a number up to the closest integer (i.e., computes the ceiling function); negative numbers are rounded up to 0.
Math.ceil(x) // x is any number or numeric expression
Computes a cosine; the return value will be between -1.0 and 1.0 radians.
Math.cos(x) // x is any number or numeric expression, in radians
Computes an exponent of $e$.
Math.exp(x) // x is a number or numeric expression to be used as exponent
Rounds a number down to the closest integer (i.e., computes the floor function); negative numbers are rounded to be more negative.
Math.floor(x) // x is any numeric value or expression
Computes a natural logarithm.
Math.log(x) // x is any numeric value or expression greater than 0
Returns the larger of two values.
Math.max(a, b) // a, b are any two numeric values or expressions
Returns the smaller of two values.
Math.min(a, b) // a, b are any two numeric values or expressions
Computes $x sup y$. (Raises its first argument to the power of its second argument and returns the result.)
Math.pow(x, y)
Computes a random number; available in 3.0 and later.
Rounds to the closest integer. In Netscape 2.0, Math.round() does not correctly round very large numbers.
Math.round(x) // x is any numeric value or expression
Computes a sine.
Math.sin(x) // x is an angle, in radians
Computes a squareroot.
Math.sqrt(x) // x is any numeric value or expression greater than or equal to 0
Computes a tangent.
Math.atan(x) // x is an angle, in radians
Represents a MIME datatype supported by the browser (or through a "helper application" or a plug-in for embedded data). Available in Netscape 3.0. See also Netscape, Plugin.
navigator.mimeTypes[i] navigator.mimeTypes["name"] navigator.mimeTypes.length
Read-only English description of the content and encoding of the type.
Reference to the Plugin object that supports this MIME type, or null, if no installed and enabled plug-in supports it. If a MIME type is supported by a plug-in, it can be embedded in a Web page with the <embed> tag; otherwise it must be output in some other way.
Read-only name of the MIME datatype (e.g., "text/html"). Value of this property can be used as an index into the navigator.mimeTypes[] array.
Read-only comma-separated list of the common filename extensions associated with this MIME type (e.g., for "text/html" the suffixes are "html, htm").
The navigator.mimeTypes[] array may be indexed numerically, or with the name of the desired MIME type (which is the value of the name property). To check which MIME types are supported by the browser, you can loop through each element in the array numerically. Or, if you just want to check whether a specific type is supported, you can write code like the following:
var show_movie = (navigator.mimeTypes["video/mpeg"] != null);
Contains properties that describe the Web browser in use; these can be used to perform platform-specific customization. There is only a single instance of the Navigator object, which you can reference through the navigator property of any Window object. Enhanced in Netscape 3.0. See also MimeType, Plugin.
navigator
Read-only string specifying the code name of the browser.
Read-only string specifying the name of the browser.
Read-only string specifying version information for the browser.
An array of MimeType objects describing the MIME types recognized and supported by the browser. Added in Netscape 3.0.
The number of elements in the mimeTypes[] array.
An array of Plugin objects describing the installed plugins. Added in Netscape 3.0.
The number of elements in the plugins[] array.
Read-only string passed by the browser as the user-agent header in HTTP requests. In Netscape 2.0 and 3.0, this property is the value of navigator.appCodeName followed by a slash and the value of navigator.appVersion (e.g., Mozilla/2.01 (Win16; I). In Microsoft Internet Explorer 3.0b1 running on Windows 95, this property has the value "Mozilla/2.0 (compatible; MSIE 3.0A; Windows 95)".
Tests whether Java is supported and enabled in the current browser.
Tests whether the data-tainting security model is supported and enabled in the current browser (true if enabled). Added in Netscape 3.0.
Numbers are a basic, primitive data type in JavaScript. In Netscape 3.0, JavaScript also supports the Number object, an object type that represents a primitive numeric value. JavaScript automatically converts between the primitive and object forms as necessary. In JavaScript 3.0, you can explicitly create a Number object with the Number() constructor, although there is rarely any need to do so. Available in Netscape 3.0. See also Math, Number().
Number.constant
The Number() constructor:
new Number(value
is actually more commonly used as a placeholder for five useful numeric constants. Note that these values are properties of the Number() constructor function itself, not of individual number objects. For example, you use the MAX_value property as follows:
biggest = Number.MAX_value
not like this:
n = new Number(2); biggest = n.MAX_value
The largest representable number.
The smallest (i.e., closest to zero, not most negative) number representable in JavaScript.
Special Not-a-Number value. JavaScript prints the Number.NaN value as NaN. Note that the NaN value always compares unequal to any other number, including itself. Thus, you cannot check for the not-a-number value by comparing to Number.NaN. Use the isNaN() function instead.
Special negative infinite value; returned on overflow. JavaScript displays the NEGATIVE_INFINITY value as -Inf. This value behaves mathematically like an infinity.
Special infinite value; returned on overflow. JavaScript displays the POSITIVE_INFINITY value as Inf. This value behaves mathematically like an infinity.
Converts a number to a string, using a specified radix (base).
number.toString(radix) // radix is an integer between 2 and 16
By contrast, the toString() method of the Number object is a method of each Number object, not of the Number() constructor function. You can use the toString method with a variable that holds a number, even though that value is not actually an object:
value = 1234; binary_value = n.toString(2);
JavaScript implicitly invokes the Number() constructor to convert the number to a temporary Number object for which the toString() method can be invoked.
A built-in datatype of the JavaScript language; serves as the "superclass" for all other JavaScript objects, and therefore methods of the Object object are also methods of all other object types. The behavior of the Object object is also shared by all other object types. When an Object object is newly created, it has no properties defined; you can add a property definition to an object simply by assigning a value to the property. Objects can also be used as associative arrays.
A number of the Object methods can be defined for any object, and will be invoked by the JavaScript system at appropriate times, to perform some sort of operation on the object (e.g., toString). JavaScript allows object syntax to be used to refer to properties and methods of primitive datatypes, such as JavaScript strings. JavaScript creates a temporary object "wrapper" for the primitive value so that the method can be invoked or the property accessed.
Enhanced in Netscape 3.0. See also Array, Boolean, Function, Number, String, Window.
new Object(); new Object(value); // Netscape 3.0 and later
In Netscape 3.0 and later, the optional value argument may specify a value of any primitive JavaScript type: a number, a boolean, a string, or a function. If no value argument is passed, this constructor returns a newly created object, which has no properties defined. If a value argument is specified, then the constructor creates and returns a Number, Boolean, String, or Function object wrapper around the primitive value.
If defined, used to implement the JavaScript assignment operator (=).
object.assign(value) // value is the value to be assigned
Evaluates a string of JavaScript code in the context of the given object. Prior to Netscape 3.0, eval() is a standalone function; in 3.0, it is a method of Object. However, in 2.0 (client-side JavaScript) it behaves as if it were a method of the Window object.
eval(code) // Netscape 3.0 window.eval(code) // Netscape 3.0
If defined, used to convert an object to a string.
Returns the primitive value of the object, if any. For objects of type Object, this method simply returns the object itself. For other object types, such as Number and Boolean, this method returns the primitive value associated with the object. This method was added in Netscape 3.0.
Defining the toString(), method, and also the less frequently used assign() and valueOf() methods of an object, is most efficiently done in a constructor method for your object type, or with the prototype object of your object.
// define a constructor for the Complex object type function Complex(x,y) { this.x = x; this.y = y; } // give it a toString() method Complex.prototype.toString = new Function("return '{' + this.x + ',' + this.y + '}';"); // Create an object of this new Complex type c = new Complex(2, 2); // Convert the object to a string, implicitly invoking the // toString() method, and display the string. alert("c = " + c);
Describes a single option displayed within a Select object. Note that although the text displayed by this option is specified outside of the <option> tag, that text must be plain, unformatted text, without any HTML tags. This is so that the text can be properly displayed in list boxes and drop-down menus that do not support HTML formatting. Enhanced in Netscape 3.0. See also Select.
select.options[i]
You can dynamically create new Option objects for display in a Select object with the Option() constructor. Once a new Option object is created, it can be appended to the list of options in a Select object by assigning it to options[options.length]. See Select.options[].
Read-only boolean that specifies whether this option is selected by default. Set by the selected attribute.
Read-only integer that specifies the index of this option within the array of options. The first Option object in the array is at index 0 and has its index property set to 0. The second Option has an index of 1, and so on.
Read/write boolean that specifies whether this option is currently selected. Its initial value is specified by the selected attribute. Can be used to test whether a given option is selected; or to select (by setting it to true) or deselect (by setting it to false) a given option. The Select.onchange() event handler is not invoked.
The text that describes the option. It is the plain text (not formatted HTML text) that follows the <option> tag. In 2.0, this property is read-only. In 3.0 it is read/write.
Read/write string that specifies the value to be passed to the server if this option is selected when the form is submitted. The initial value is specified by the value attribute.
An Option object is created by an <option> tag within a <select> which is itself within a <form>. Multiple <option> tags typically appear within the <select>.
<form ...> <select ...> <option [ value="value" ] the value returned when the form is submitted [ selected ] > specifies whether this option is initially selected plain_text_label the text to display for this option ... </select> ... </form>
An object that contains references to other JavaPackage objects and to JavaClass objects. Each JavaPackage object represents a node in the tree of package names. The Packages property refers to a JavaPackage object which is the root of this package name hierarchy.
The Packages object is a "global" variable in JavaScript; a read-only reference to a JavaPackage object, it is defined as a property of all Window objects. Thus, you can always refer to it simply as Packages, rather than explicitly accessing it through a particular Window object.
Note that the Window object also contains "global" properties named java, netscape, and sun, all of which are synonyms for the properties of the Packages object. So instead of writing Packages.java.lang.Math, for example, you can just write java.lang.Math.
Available in Netscape 3.0. See also JavaClass, JavaObject, JavaPackage.
Reference to a JavaPackage object that represents the top node of the java.* package hierarchy.
Reference to a JavaPackage object that represents the top node of the netscape.* package hierarchy.
Reference to a JavaPackage object that represents the top node of the sun.* package hierarchy.
Parses and returns the first number that occurs in s (i.e., converts a string to a number). Parsing stops, and the value is returned, when parseFloat() encounters a character in s that is not a valid part of the number (i.e., a sign, a digit, decimal point, exponent, etc.). If s does not begin with a number that parseInt() can parse, then the function returns NaN, a reserved value that represents "not-a-number."
parseFloat() is a built-in JavaScript function; not a method of any object. Buggy in Netscape 2.0. See also isNaN(), parseInt().
parseFloat(s) // s is the string to be parsed and coverted to a number
Parses and returns the first number that occurs in the string s (i.e., it converts a string to an integer). Parsing stops, and the value is returned, when parseInt() encounters a character in s that is not a valid numeral for the specified radix. If s does not begin with a number that parseInt() can parse, then the function returns NaN, a reserved value that represents "not-a-number."
Specifying a radix of 10 makes the parseInt() parse a decimal number. The value 8 specifies that an octal number (using digits 0 through 7) is to be parsed. The value 16 specifies a hexadecimal value, using digits 0 through 9 and letters A through F. radix can be any value between 2 and 36.
If radix is 0, or if it is not specified, parseInt() tries to determine the radix of the number from s. If s begins with 0x, then parseInt() parses the remainder of s as a hexadecimal number. If s begins with a 0, then parseInt() parses the number in octal. Otherwise, if s begins with a digit 1 through 9, then parseInt() parses it as a decimal number.
parseInt is a built-in JavaScript function, not a method of any object. Buggy in Netscape 2.0. See also isNaN(), parseFloat().
parseInt(s) parseInt(s, radix) //s is the string to be parsed //radix is the integer base of the number to be parsed
A text input field intended for input of sensitive data, such as passwords. As the user types characters, only asterisks appear. The value property is a read/write string that initially contains the value specified by the value attribute; it specifies the data to be transmitted if the user does not type anything. For security reasons, this default value is the only thing that JavaScript has access to. The user's input is transmitted to the server when the form is submitted, but that input does not appear in this property, and setting this property has no effect on the value transmitted. Enhanced in Netscape 3.0. See also Element, Form, Text.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the Password object.
Read-only string, set by the HTML name attribute, that specifies the name of the Password object. This is also the name that can be used to reference the Password object as a property of its form.
Read-only string that specifies the type of this form element. For Password objects, it has the value "password." Available in Netscape 3.0 and later.
Read/write string, initially set by the HTML value attribute. For security, the user's input is not available through this property, and setting this property does not affect the data transmitted with the form.
Removes the keyboard focus from the Password object.
Sets the keyboard focus to the Password object. When focus is set, all keystrokes are automatically entered into this object.
A Password object is created with a standard HTML <input> tag:
<form> ... <input type="password" specifies that this is a Password object [ name="name" ] a name that can later be used to refer to this object specifies the name property [ value="default" ] the default value transmitted when the form is submitted [ size=integer ] how many characters wide the object is > ... </form>
Represents a plug-in application that has been installed in the browser. Available in Netscape 3.0. See also Netscape, MimeType.
navigator.plugins[i] navigator.plugins['name'] navigator.plugins.length
Read-only string that contains a human-readable description of the plug-in, specified by the plug-in itself. This property may specify a full product name, information about the vendor and version, and so on.
Read-only string that specifies the name of the disk file that contains the plug-in code.
Read-only array of MimeType objects, one for each MIME type supported by the plug-in.
The number of elements in the mimeTypes[] array.
Read-only string that specifies the name of the plug-in. This is generally a much shorter string than description. The value of this property may be used as an index into the navigator.plugins[] array.
The navigator.plugins[] array may be indexed numerically when you want to loop through the complete list of installed plug-ins, looking for one that meets your needs. The navigator.plugins[] array can also be indexed by plug-in name, however. That is, if you want to check whether a specific plug-in is installed in the user's browser, you might use code like this:
document.write( navigator.plugins("Shockwave") ? "<EMBED src="movie.dir' height=100 WIDTH=100>" : "You don't have the Shockwave plugin!" );
The name used as an array index with this technique is the same name that appears as the value of the name property.
Represents a single graphical radio button in an HTML form. Note that the text that appears next to a Radio button is not part of the Radio object itself, and must be specified externally to the <input> tag. The Radio button object is always used in groups of mutually-exclusive options that have the same name. To references on Radio objects within a group, use the syntax below.
Note that only one Radio object in a group may contain the checked attribute, which sets the initial values of the checked and defaultChecked properties (true for that object and false for all other Radio buttons in the group). If none of the objects have the checked attribute, then the first one in the group will be checked (and defaultChecked) by default.
In Netscape 2.0, there is a bug in how Radio objects in a group are assigned to an array. The workaround is to always assign an event-hander, if only a dummy one, to all of your Radio objects that will be manipulated with JavaScript. Enhanced in Netscape 3.0. See also Checkbox, Element, Form.
form.radio_name[j] form.radio_name.length form.elements[i][j] form.elements[i].length form.elements['radio_name'][j] form.elements['radio_name'].length
Read/write boolean value that specifies whether the button is checked or not; can be examined to determine the button's state, or be set to select or deselect the button. Setting checked changes the appearance of the button, but does not invoke onClick.
Read-only Boolean that specifies the initial state of the radio button.
Read-only reference to the Form object that contains the Radio object.
Read-only string, set by the HTML name attribute, that specifies the name of the Radio button.
Read-only string that specifies the type of this form element. For Radio objects, it has the value "radio". Available in Netscape 3.0 and later.
Read/write string, initially set by the HTML value attribute, which specifies the value passed to the server if the Radio button is selected when the form is submitted. Each Radio object in a group should specify a distinct value.
Invoked when the Radio button is clicked; allows you to specify JavaScript code to be executed when the button is checked or "un-checked."
<input type="radio" a definition of the handler onClick="handler-statements"> radio.onclick a reference to the handler radio.onclick(); an explicit invocation of the handler
A Radio object is created with a standard HTML <input> tag, with the addition of the new onClick attribute. Radio objects are created in groups by specifying multiple <input> tags that have the same name attribute (mandatory if the radio is part of a form that will submit data to a CGI script). Specifying a name attribute sets the name property, and also allows you to refer to the button by name (instead of as a member of the form elements array).
<form> ... <input type="radio" specifies that this is a radio button [ name="name" ] a name that can later be used to refer to this button or to the group of buttons with this name; specifies the name property [ value="value" ] the value returned when this button is selected; specifies the value property [ checked ] specifies that the button is initially checked; specifies the defaultChecked property [ onClick="handler" ] JavaScript statements to be executed when the button is clicked > label the HTML text that should appear next to the button ... </form>
The Reset object has the same properties and methods as the Button object, but is used only to reset a form's values (to their defaults). For most elements this means to the value specified by the HTML value attribute. If no initial value was specified, then a click on the Reset button will "clear" any user input from those objects. If no value attribute is specified for a Reset object, it will be labeled "Reset." Enhanced in Netscape 3.0. See also Button, Element, Form.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the Reset object.
Read-only string, set by the HTML name attribute, that specifies the name of the Reset object. This is also the name that can be used to reference the Reset object as a property of its form.
Read-only string that specifies the type of this form element. For Reset objects, it has the value "reset." Available in Netscape 3.0 and later.
Read-only string, set by the HTML value attribute, that specifies the text to appear in the button. If no value is specified, then (in Netscape) the button will be labelled "Reset" by default.
Invoked when the Reset button is clicked. Defined by the onClick attribute of the HTML <input> tag that defines the Reset button. The value of this attribute may be any number of JavaScript statements, separated by semicolons; these statements will be executed when the user clicks on the Reset button. In Netscape 2.0, there is no way for the onclick() event handler to prevent the fields from being reset. However, in 3.0, the event handler may return false to prevent the Reset object from resetting the form.
<input type="reset" a definition of the handler onClick="handler-statements"> reset.onclick a reference to the handler reset.onclick(); an explicit invocation of the handler
A Reset object is created with a standard HTML <input> tag, with the addition of the onClick attribute:
<form> ... <input type="reset" specifies that this is a Reset button [ value="label" ] the text that is to appear within the button specifies the value property. [ name="name" ] a name that can later be used to refer to the button specifies the name property [ onClick="handler" ] JavaScript statements to be executed when the button is clicked > ... </form>
Represents a graphical list of choices from which the user may select. If the multiple attribute is present in the HTML definition of the object, then the user may select any number of options from the list. If that attribute is not present, then the user may select only one option, and options have a "radio button" (i.e., mutually exclusive toggle) behavior.
If the size attribute has a value greater than 1, or if the multiple attribute is present, Select objects are displayed in a list box that is size lines high in the browser window. If size is smaller than the number of options, then the list box will include a scrollbar so that all the options are accessible. On the other hand, if size is specified as 1, and multiple is not specified, then the currently selected option is displayed on a single line and the list of other options is made available through a drop-down menu.
Enhanced in Netscape 3.0. See also Element, Form, Option.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the Select object.
Read-only integer that specifies the number of elements in the options[] array (i.e., the number of options that appear in the Select object).
Read-only string, set by the HTML name attribute, that specifies the name of the select object. This is also the name that can be used to reference the Select object as a property of its form.
An array of Option objects, each of which describes one of the options displayed within the Select object. The options.length property specifies the number of elements in the array, as does the select.length property. See the Option object for further details.
Read-only (read/write in 3.0) integer that specifies the index of the selected option within the Select object. If the Select object has its multiple attribute set and allows multiple selections, then this property only specifies the index of the first selected item or -1 if none are selected.
Read-only string that specifies the type of this form element. For Select objects, it has the value "select-one" or "select-multiple." Available in Netscape 3.0 and later.
Invoked when the user selects or deselects an item. Defined by the onChange attribute of the HTML <select> tag that defines the Select object. The value of this attribute may be any number of JavaScript statements, separated by semicolons; these statements will be executed whenever the user selects or deselects an option. Buggy to the point of uselessness in Netscape 2.0.
<select onChange="handler-statements"> a definition of the handler select.onchange a reference to the handler reset.onchange(); an explicit invocation of the handler
A Select object is created with a standard HTML <select> tag, with the addition of the new onChange, onBlur, and onFocus event-handler attributes. Options to appear within the Select object are created with the <option> tag:
<form> ... <SELECT name="name name identifying this object; specifies name property [ SIZE=integer ] number of visible options in select object [ MULTIPLE ] multiple options may be selected, if present [ onChange="handler" ] invoked when the selection changes [ onBlur="handler" ] invoked when object loses focus [ onFocus="handler" ] invoked when object gains focus > <option value="value1" [selected]> option_label1 <option value="value2" [selected]> option_label2 . . other options here . </select> ... </form>
Exists to provide methods for operating on string values (a basic JavaScript data type). The String class defines a number of methods, most of which simply make a copy of the string with HTML tags added before and after.
The string datatype and the String object are not the same, but in Netscape 2.0 are indistinguishable. In Netscape 3.0, you can use the typeof operator to distinguish them (a string has type "string" and a String object has type "object"); however, you can use them interchangeably because JavaScript converts between these two types whenever necessary. When you invoke a String object method on a string value, JavaScript converts that value to a temporary String object, allowing the method to be invoked. In Netscape 3.0, you can use the String object constructor method to create String objects that are not temporary, and that can actually be used by your programs:
new String(value) // Netscape 3.0 only
Enhanced in Netscape 3.0.
The number of characters in the string. For any string s, the index of the last character is s.length-1.
See Function.prototype.
Returns a copy of the string, enclosed within <a name="name"> and </a> HTML tags. The name attribute of the </a> tag is set to the name argument. If the resulting string is appended to an HTML document (with Document.write() for example), it defines an anchor, with a name of name, which can be the target of a hypertext link.
Returns a copy of the string, enclosed between <big> and </big> HTML tags.
Returns a copy of the string, enclosed between <blink> and </blink> HTML tags.
Returns a copy of the string, enclosed between <b> and </b> HTML tags.
Extracts the nth character from a string. The first character of the string is numbered 0. If n is not between 0 and string.length-1, then this method returns an empty string. Note that JavaScript does not have a character datatype that is distinct from the string type, so the returned character is a string of length 1.
string.charAt(n) //n is the index of the character to be returned
Returns a copy of the string, enclosed between <tt> and </tt> HTML tags.
Returns a copy of the string, enclosed between <font color="color"> and </font> HTML tags. The color argument is a string specifying the color name or value to be used as the value of the color attribute in the <font> HTML tag. Colors are specified either as one of the standard color names recognized by JavaScript, or as red, green, and blue color values, expressed as six hexadecimal digits (RRGGBB).
string.fontcolor(color)
Returns a copy of the string, enclosed between <font size="size"> and </font> HTML tags. The size argument is an integer between 1 and 7 or a string that begins with a + or - sign followed by a digit between 1 and 7. If an integer is specified, it is an absolute font size specification. If a string is specified, the font specification is relative to the <basefont> size.
string.fontsize(size)
Searches the string for an occurrence of substring. The search begins at position start within string, or at the beginning if no start is specified. start is an integer between 0 and string.length-1. Returns the position of the first occurrence of substring after the start position, or -1 if no occurrence is found.
string.indexOf(substring) string.indexOf(substring, start)
Returns a copy of the string, enclosed between <i> and </i> HTML tags.
Searches the string backwards for an occurrence of substring. The search begins at position start within string, or at the end, if no start is specified. start is an integer between 0 and string.length-1. Returns the position of the first occurrence of substring before the start position, or -1 if no occurrence is found.
string.lastIndex(substring) string.lastIndex(substring, start)
Returns a copy of the string, enclosed between <a href="size"> and </a> HTML tags. href specifies the URL target of the hypertext link that is to be added to the string. This string argument specifies the value of the HREF attribute of the <a> HTML tag.
string.link(href)
Returns a copy of the string, enclosed between <small> and </small> HTML tags.
Converts a string to an array of strings, using a specified delimiter character/string at which the string will be split. If no delimiter is specified, then the returned array has only one element, the string itself. Note that the String.split() method is the inverse of the Array.join() method.
string.split() string.split(delimiter)
Returns a copy of the string, enclosed within <strike> and </strike> HTML tags.
Returns a copy of the string, enclosed within <sub> and </sub> HTML tags.
Extracts a substring of a string. from is a value between 0 and string.length-1. to is an optional integer that is one greater than the position within string of the last character of the desired substring. to must be between 1 and string.length. The character at position from is included in the substring, while the character at position to is not. The returned string contains characters copied from positions from to to-1 of string.
string.substring(from, to)
Returns a copy of the string, enclosed within <sup> and </sup> HTML tags.
Returns a copy of the string, with all characters converted to lowercase.
Returns a copy of the string, with all characters converted to uppercase.
Returns the string value contained in the String object; Netscape 3.0 and later. See Object.valueOf().
A number of the String methods are used for creating HTML:
link_text = "My Home Page".bold(); document.write(link_text.link("http://www.djf.com/~david"));
The code above code embeds the following string into the HTML document that is currently being parsed:
<A HREF="http://www.djf.com/~david"><B>My Home Page</B></A>
The following code extracts the 3rd through 5th characters of a string and converts them to upper-case letters:
s.substring(2,5).toUpperCase();
When a Submit button is clicked on, it submits the data in the form that contains the button to the server specified by the form's action attribute, and loads the resulting HTML page sent back by that server. The Submit object has the same properties and methods as the Button object. If no value attribute is specified for a Submit object, it will be labelled "Submit Query."
Form data may also be submitted by invoking the Form.submit() method. The Submit.onclick() event handler can define additional JavaScript statements to be executed when a Submit button is clicked; to cancel a form submission, use Form.onsubmit().
Enhanced in Netscape 3.0. See also Button, Element, Form.
form.name form.elements[i] form.elements['name']
Read-only reference to the Form object that contains the Submit object.
Read-only string, set by the HTML name attribute, that specifies the name of the Submit object. This is also the name that can be used to reference the Submit object as a property of its form.
Read-only string that specifies the type of this form element. For Submit objects, it has the value "submit." Available in Netscape 3.0 and later.
Read-only string, set by the HTML value attribute, that specifies the text to appear in the button. If no value is specified, then (in Netscape) the button will be labelled "Submit Query" by default.
Invoked when the Submit button is clicked. Defined by the onClick attribute of the HTML <input> tag that defines the Submit button. The value of this attribute may be any number of JavaScript statements, separated by semicolons; these statements will be executed when the user clicks on the Submit button. In Netscape 2.0, there is no way for the onclick() event handler to cancel the submit action; use the Form.onsubmit() event handler to perform input validation and to cancel form submission if necessary.
<input type="submit" a definition of the handler onClick="handler-statements"> submit.onclick a reference to the handler submit.onclick(); an explicit invocation of the handler
A Reset object is created with a standard HTML <input> tag, with the addition of the onClick attribute:
<form> ... <input type="submit" specifies that this is a Submit button [ value="label" ] the text that is to appear within the button; specifies the value property [ name="name" ] a name that can later be used to refer to the button; specifies the name property [ onClick="handler" ] JavaScript statements to be executed when button is clicked > ... </form>
Taints a value or window (when the data tainting security model is in effect). taint() does not taint the value it is passed; instead, it returns a tainted copy of that value, or a tainted reference to that value for object types. (Note that taint is associated with primitive values and with references to objects, not with the objects themselves.)
Sometimes taint is carried not by data values, but by the control flow of a program. In this case, you may want to add taint to the entire window in which JavaScript code runs by calling taint() with no arguments. Available in Netscape 3.0. See also untaint().
taint() taint(value)
Represents a text input field in a form. The size attribute specifies the width, in characters, of the input field as it appears on the screen, and the maxlength attribute specifies the maximum number of characters the user will be allowed to enter. You can read the value property to obtain the user's input, or you can set it to display arbitrary (unformatted) text in the input field. Use the Password object instead of the Text object when the value you are asking the user to enter is sensitive information. Use a Textarea object to allow the user to enter multiple lines of text.
When a form contains only one Text or Password object, then the form will automatically be submitted if the user strikes the Return key in that Text or Password object. Enhanced in Netscape 3.0. See also Element, Form, Password, Textarea.
form.name form.elements[i] form.elements['name']
Read-only string that specifies the initial value to appear in the input field. Specified by the value attribute of the <input> tag.
Read-only reference to the Form object that contains the Text object.
Read-only string, set by the HTML name attribute, that specifies the name of the Text object. This is also the name that can be used to reference the Text object as a property of its form.
Read-only string that specifies the type of this form element. For Text objects, it has the value "text." Available in Netscape 3.0 and later.
Read/write string that specifies the value contained in the input field (which is also the value sent to the server when the form is submitted). The initial value of this property is specified by the value attribute of the <input> tag.
Removes the keyboard focus from the text object. In Netscape 2.0, the blur() method invokes the onblur() event handler of the Text object. This is inconsistent with the behavior of other event handlers, which are only invoked in response to user actions.
Sets the keyboard focus to the Text object. When focus is set, all keystrokes are automatically entered into this object.
Highlights all the text in the Text object, and enters a special mode so that future input replaces the highlighted text.
The value of the following event handlers may be any number of JavaScript statements, separated by semicolons, which are executed when the handler is invoked.
Invoked when a user action causes the Text object to lose the keyboard focus. Defined by the onBlur attribute of the HTML <input> tag that defines the Text object.
<input type="text onblur" a definition of the handler onClick="handler-statements"> text.onblur a reference to the handler text.onblur(); an explicit invocation of the handler
Invoked when the user changes the value in the Text object and then "commits" those changes by moving the keyboard focus elsewhere. Defined by the onChange attribute of the HTML <input> tag that defines the Text object. This event handler is not invoked when the value property of a Text object is set by JavaScript.
<input type="text onchange" a definition of the handler onChange="handler-statements"> text.onchange a reference to the handler text.onchange(); an explicit invocation of the handler
Invoked when a user action causes the Text object to gain the keyboard focus. Defined by the onFocus attribute of the HTML <input> tag that defines the Text object. Note that the onfocus event handler is not invoked by the Text.focus() method.
<input type="text onfocus" a definition of the handler onFocus="handler-statements"> text.onfocus a reference to the handler text.onfocus(); an explicit invocation of the handler
A Text object is created with a standard HTML <input> tag, with the addition of optional attributes for event handlers:
<form> ... <input type="text" specifies that this is a Text object [ name="name" ] a name that can later be used to refer to this object; specifies the name property [ value="default" ] the default value transmitted when form is submitted; specifies the defaultValue property [ size=integer ] how many characters wide the object is [ maxlength=integer ] max allowed number of input characters [ onBlur="handler" ] the onblur() event handler [ onChange="handler" ] the onchange() event handler [ onFocus="handler" ] the onfocus() event handler > ... </form>
Represents a (mutli-line) text input field in a form. The name attribute specifies a name for the object. This is mandatory if the form is to be submitted, and also provides a convenient way to refer to the Textarea object from JavaScript code.
Read the value property to obtain the user's input, or set it to display arbitrary (unformatted) text in the Textarea. The initial value of the value property (and the permanent value of the defaultValue property) is the text that appears between the <textarea> and </textarea> tags.
If you need only a single line of input text, use the Text object. If the text to be input is sensitive information, such as a password, use the Password object. Enhanced in Netscape 3.0. See also Element, Form, Password, Text.
form.name form.elements[i] form.elements['name']
Read-only string that specifies the initial value to appear in the input field. This default value is whatever plain text appears between the <textarea> and </textarea> tags.
Read-only reference to the Form object that contains the Textarea object.
Read-only string, set by the HTML name attribute, that specifies the name of the Textarea object. This is also the name that can be used to reference the Textarea object as a property of its form.
Read-only string that specifies the type of this form element. For Textarea objects, it has the value "textarea." Available in Netscape 3.0 and later.
Read/write string that specifies the value contained in the Textarea (which is also the value sent to the server when the form is submitted). The initial value of this property is the same as the defaultValue property.
Removes the keyboard focus from the text object.
Sets the keyboard focus to the Textarea object. When focus is set, all keystrokes are automatically entered into this object.
The value of the following event handlers may be any number of JavaScript statements, separated by semicolons, which are executed when the handler is invoked.
Invoked when a user action causes the Textarea object to lose the keyboard focus. Defined by the onBlur attribute of the HTML <textarea> tag that defines the Textarea object. Note that the onblur() event handler is not invoked by the Textarea.blur() method.
<textarea onblur="handler-statements"> a definition of the handler </textarea> text.onblur a reference to the handler text.onblur(); an explicit invocation of the handler
Invoked when the user changes the value in the Textarea object and then "commits" those changes by moving the keyboard focus elsewhere. Defined by the onChange attribute of the HTML <textarea> tag that defines the Text object. This event handler is not invoked when the value property of a Text object is set by JavaScript.
<textarea onchange="handler-statements"> a definition of the handler </textarea> text.onchange a reference to the handler text.onchange(); an explicit invocation of the handler
This event handler is not invoked for every keystroke in the Textarea object, but only when the user completes an edit.
Invoked when a user action causes the Textarea object to gain the keyboard focus. Defined by the onFocus attribute of the HTML <textarea> tag that defines the Textarea object. Note that the onfocus event handler is not invoked by the Text.focus() method.
<textarea onfocus="handler-statements"> a definition of the handler </textarea> text.onfocus a reference to the handler text.onfocus(); an explicit invocation of the handler
A Textarea object is created with standard HTML <textarea> and </textarea> tags, with the addition of optional attributes for event-handlers. Note that the wrap attribute, which specifies how long lines should be handled, has three legal values: off specifies that they should be left as is; virtual specifies that they should be displayed with line breaks but transmitted without; physical specifies that they should be displayed and transmitted with line breaks inserted.
<form> ... <textarea [ name="name" ] a name that can later be used to refer to this object [ rows=integer ] how many lines tall the object is [ cols=integer ] how many characters wide the object is [ wrap=off|virtual|physical ] how word wrapping is handled [ onBlur="handler" ] the onblur() event handler [ onChange="handler" ] the onchange() event handler [ onFocus="handler" ] the onfocus() event handler > plain_text The initial text; specifies defaultValue </textarea> ... </form>
The unescape() function is a built-in part of JavaScript; it is not a method of any object. unescape() decodes a string encoded with escape() and returns the decoded copy.
unescape(s) // s is the string to be decoded or "unescaped"
Available in Netscape 2.0. See also escape(), String.
unescape decodes s by finding and replacing character sequences of the form %xx, where xx is two hexadecimal digits. Each such sequence is replaced by the single character represented by the hexadecimal digits in the Latin-1 encoding. Thus, unescape() decodes the string:
Hello%20World%21
to:
Hello World!
Untaints a value or window (when the data tainting security model is in effect). untaint() does not remove the taint of the value it is passed; instead, it returns an untainted copy of that value, or an untainted reference to that value for object types. (Note that taint is associated with primitive values and with references to objects, not with the objects themselves.)
JavaScript automatically associates taint with data values that are potentially private, and that should not be "stolen" by scripts. If you need to allow these values to be exported by scripts, you must use untaint() to make untainted copies.
Sometimes taint is carried not by data values, but by the control flow of a program. In this case, you may need to remove taint from an entire window in which JavaScript code runs. You can do this by calling untaint() with no arguments. Note, however, that you can only do this if the window carries only the taint of the script that calls untaint(). If the window has also been tainted by other scripts, then it cannot be untainted. Available in Netscape 3.0. See also taint().
untaint() untaint(value)
Represents a Web browser window or frame. Since JavaScript code is evaluated in the context of the Window object in which it is running, the Window object must contain references (or references to references) to all the other JavaScript objects of interest (i.e., it is the root of a JavaScript "object hierarchy"). Many of the properties of the Window object are references to other important JavaScript objects. Most of these properties refer to an object particular to the window. The location property of a Window, for example, refers to the Location object of the window. Still other Window properties (e.g., navigator) refer to "global" objects, while a couple refer only to the window itself.
In client-side JavaScript, no special syntax is required to refer to the current window, and you can use the properties of that window object as if they were variables (e.g., you can write document rather than window.document). Similarly, you can use the methods of the current window object as if they were functions (e.g., alert() instead of window.alert()).
self the current window window the current window
To refer to a frame within a window, use:
frames[i] // or self.frames[i] window.frames[i]
To refer to the parent window (or frame) of a frame, use:
parent // or self.parent, window.parent window.parent // parent of specified frame
To refer to the top-level browser window from any frame contained within it, use:
top // or self.top, window.top
New top-level browser windows are created with the Window.open() method. When you call this method, save the return value of the open() call in a variable, and use that variable to reference the new window.
Enhanced in Netscape 3.0. See also Frame.
Read-only boolean that specifies whether a window has been closed. Available in Netscape 3.0.
Read/write string that specifies the default message to appear in the status line.
Reference to the Document object contained in the window.
An array of the frames contained by this window. The frames.length property contains the number of elements in the frames[] array, as does the window.length property.
window.frames[i] window.frames.length
Reference to the History object for this window.
Reference to the JavaPackage object that is the top of the package name hierarchy for the core java.* packages that comprise the Java language. Available in Netscape 3.0.
The number of elements in the frames[] array. Same as frames.length. Read-only.
Reference to the Location object for this window.
Reference to an object holding various mathematical functions and constants. Available in Netscape 3.0.
String that contains the name of the window. The name is optionally specified when the window is created with the open() method. In Netscape 2.0, this property is read-only; in 3.0 and later, it is read/write.
Reference to the Netscape object that applies to this and all other windows.
Reference to the JavaPackage object that is the top of the package name hierarchy for the core netscape.* Java packages from Netscape. Available in Netscape 3.0.
Read-only property that refers to the Window object that contained the document that called open() to create this window. Available in Netscape 3.0.
Reference to the JavaPackage object that represents the top of the Java package name hierarchy. Available in Netscape 3.0.
Reference to the parent window or frame of the current window. Only useful when the current window is a frame rather than a top-level window.
Reference to the window itself. A synonym for window.
Read/write string that specifies the current contents of the status line.
Reference to the JavaPackage object that is the top of the package name hierarchy for the sun.* Java packages from Sun Microsystems. Available in Netscape 3.0.
Reference to the top-level window that contains the current window. Only useful when the current window is a frame rather than a top-level window.
Reference to the window itself. A synonym of self.
Displays a simple message in a dialog box. The box has an OK button, and is non-modal (i.e., doesn't interrupt program execution).
window.alert(message)
Takes keyboard focus from the top-level browser window; this sends the window to the background on most platforms.
Cancels a pending timeout operation. The timeoutId argument is a value returned by the call to setTimeout() and identifies which block of deferred code to cancel.
window.clearTimeout(timeoutId)
Closes a window.
Asks a yes-or-no question using a dialog box. Returns true if the user clicks the OK button, false if the user clicks Cancel.
window.confirm(question)
Gives the top-level browser window keyboard focus; this brings the window to the front on most platforms.
Looks up an existing window or opens up a new one. Buggy in Netscape 2.0.
window.open([url, [name, [features]]])
If the name argument specifies the name of an existing window, then a reference to that window is returned. The returned window will display the specified url, but the features will be ignored. If the url is the empty string, a blank window is opened. If name does not refer to an existing window, it specifies the name of the new window; name can be used as the value of a target attribute of an <a> or <form> tag to force documents to be displayed in the window. features is a comma-separated list of features to appear in the window; if this argument is empty or not specified, then all features will be present in the window. If features specifies any one feature, then any feature that does not appear in the list will not appear in the window. The string should not contain any whitespace; each element has the form:
feature[=value]
The available features are:
the browser toolbar
the input field for entering URLs into the browser
directory buttons, such as "What's New" in Netscape
the status line the browser menubar
if this feature is present and not set to no, then the window will not have resize handles around its border
must be followed by a value that specifies the width of the window in pixels
must be followed by a value that specifies the height of the window in pixels Displays the specified (plain text) message in a dialog box that also contains a text input field and three buttons (OK, Clear, and Cancel). It should ask the user to enter the information you want. The optional default is a string or integer that will initially be displayed in the input field. If the default argument is not passed, or if its value is null, then prompt() displays the string "<undefined>". Pass the empty string ("") to make prompt() display an empty input box.
window.prompt(message) window.prompt(message, default)
Selecting the Cancel button causes prompt() to return null; OK returns the text value in the input field; Clear erases the field. Scrolls the document displayed in the Window so that the specified x and y coordinates appear in the upper-left corner. scroll(0,0) specifies the top-left corner of the document.
window.scroll(x, y) // x, y are coords to scroll to
Executes string of JavaScript code after a specified amount of time (delay milliseconds) elapses. Returns an opaque value (a "timeout id") that can be passed to the clearTimeout() method to cancel the execution of code.
window.setTimeout(code, delay)
The value of the following event handlers may be any number of JavaScript statements, separated by semicolons, which are executed when the handler is invoked.
Invoked when a top-level window loses focus. Defined by specifying the onBlur attribute of the <body> or <frameset> tags of the document or frameset that occupies the top-level window. May also be defined by assigning a function to the onblur property of the Window object.
<body a definition of the handler [ onBlur="JavaScript statements" ] . . . > <frameset another way to define the handler [ onBlur="JavaScript statements" ] . . . > window.onblur=handler-func defining the handler directly window.onblur() an explicit invocation of the handler
Invoked when a JavaScript error occurs. The default JavaScript error handler displays an error dialog; you can customize this behavior by providing your own onerror() event handler. Define it for a window by setting the onerror property of a Window object to an appropriate function; unlike other event handlers in JavaScript, onerror() cannot be defined in an HTML tag. You register an onerror() event handler like this:
window.onerror="handler-function
Netscape invokes the handler like this:
window.onerror(message, url, line)
message is the error message; url is the URL of the document in which the error occurred; line is the line number at which the error occurred. When the onerror() handler is invoked, it is passed these three arguments to do with as it will. You can turn off error handling for a window by setting the onerror property of the window to null.
Invoked when the top-level window receives focus. Defined by specifying the onFocus attribute of the <body> or <frameset> tags of the document or frameset that occupies the top-level window. May also be defined by assigning a function to the onfocus property of the Window object.
<body a definition of the handler [ onFocus="JavaScript statements" ] . . . > <frameset another way to define the handler [ onFocus="JavaScript statements" ] . . . > window.onfocus=handler-func defining the handler directly window.onfocus() an explicit invocation of the handler
Invoked when the document (or frameset) is fully loaded. Defined by specifying the onLoad attribute of the <body> or <frameset> tags of that window. May also be read and invoked through the Window object. Buggy in Netscape 2.0.
<body a definition of the handler [ onLoad="JavaScript statements" ] . . . > <frameset another way to define the handler [ onLoad="JavaScript statements" ] . . . > window.onload=handler-func defining the handler directly window.onload() an explicit invocation of the handler
Invoked when the browser leaves the document or frameset. Defined by specifying the onUnload attribute of the <body> or <frameset> tags of that window. May also be read and invoked through the Window object.
<body a definition of the handler [ onUnload="JavaScript statements" ] . . . > <frameset [ rows="row sizes" ] another way to define the handler [ cols="column sizes" ] [ onUnload="JavaScript statements" ] . . . > window.onunload=handler-func defining the handler directly window.onunload() an explicit invocation of the handler