This appendix describes JavaScript's built-in objects and functions. The
browser creates some of the objects in response to HTML elements in your Web
page, and others are simply part of the language and available all the time.

JavaScript defines several intrinsic objects. Like the objects that you can
define, they have methods and properties. They may also have event handlers,
which are JavaScript expressions that JavaScript executes when a specific kind
of event occurs.

The anchors array is an array of anchor objects. It is a property of the
document object. Anchor objects are reflections of A elements that have a NAME
attribute:

<A NAME="anchorName">anchorText</A>

You can add anchors to the anchors array, but you cannot remove, replace, or
modify them.

The anchors array has one property:

length

The number of entries in the anchors array. You cannot
change this property directly, but you can create new anchors with the
string anchor() method; such newly created anchors are added to the
anchors array.

A checkbox object is a reflection of an INPUT element with a TYPE attribute
of "checkbox":

<INPUT TYPE="checkbox">

checkbox objects are members of the containing form's elements array.

A checkbox object has four properties:

checked

A Boolean value that indicates whether the checkbox object
is on or off. The checkbox object is on if checked is true. You can change
checked at any time. Changing checked changes the appearance of the
display immediately.

Default-Checked

A Boolean value that indicates the default state of the
checkbox object. The default state of the checkbox object is on if
defaultChecked is true. The initial value of defaultChecked is set from
the INPUT tag's CHECKED attribute. You can change defaultChecked at any
time. Changing defaultChecked has no effect on the appearance of the
display.

name

The value of the INPUT tag's NAME attribute. You can change
it at any time.

value

The value of the INPUT tag's VALUE attribute. value is "on"
in the absence of a VALUE attribute. The browser returns this property to
the server if the user selected the checkbox. value is not part of the
displayed object. You can change this property at any time.

Date objects provide a mechanism for dealing with dates and time. At this
time, JavaScript does not support dates before January 1, 1970 or after December
31, 1999.

There are three ways to create a Date object:

Date();

Uses the current local date and time.

Date(string);

Uses a string of "month day, year hours:minutes:seconds";
you can omit the time portion.

Date(year, month, day, hours, minutes, seconds);

The parameters are integers; you can omit the time portion.

Date objects have 20 methods:

getDate()

Returns the day of the month from the date object. The value
returned is between 1 and 31.

getDay()

Returns the day of the week from the date object. The value
returned is between 0 (Sunday) and 6 (Saturday).

getHours()

Returns the hour from the date object. The value returned is
between 0 and 23.

getMinutes()

Returns the minutes from the date object. The value returned
is between 0 and 59.

getMonth()

Returns the month from the date object. The value returned
is between 0 (January) and 11 (December).

getSeconds()

Returns the seconds from a date object. The value returned
is between 0 and 59.

getTime()

Returns the number of milliseconds from January 1, 1970,
00:00:00.000 to the time in the date object.

GetTimeZoneOffset()

Returns the difference, in minutes, between local time and
Greenwich Mean Time (GMT).

getYear()

Returns the year from a date object. The value returned is
the year minus 1900.

Date.parse (dateString)

Returns the number of milliseconds between date-String and
January 1, 1970, 00:00:00.000 local time. The string may be of the form
DDL dd MMM YYYY HH:MM:SS TZ. DDD is the first three letters of the
day of the week. dd is the day of the month from 1 to 31.
MMM is the first three letters of the month. YYYY is the
year. HH is the hour. MM is the minute. SS is the
second. TZ is the time zone. parse() recognizes GMT, UTC, and the
continental United States time zone abbreviations. You can express the
time zone as GMT+HHMM, indicating an offset of HH hours and
MM minutes from GMT. If you omit the time zone, the browser assumes
local time.

SetDate (number)

Sets the day of the month in a date object to number. If
number is inappropriate to the date, JavaScript automatically adjusts the
month and date. For example, if the month in a Date object is April and
you call setDate()to set the date to 31, the date will be May 1 instead of
April 31.

SetHours (number)

Sets the hours in a date object to number.

SetMinutes (number)

Sets the minutes in a date object to number.

SetMonth (number)

Sets the month in a date object to number. If the
resulting combination of month and date is inappropriate, JavaScript
automatically adjusts the month and date. For example, if the date is May
31, and you use setMonth() to set the month to April, the date becomes May
1, not April 31st.

setSeconds (number)

Sets the seconds in a date object to number.

setTime (number)

Sets the date and time in a date object to the value
indicated by number. number is the number of milliseconds
since 1 January 1970 00:00:00.000

setYear (number)

Sets the least significant two digits of year in the date
object to number. If the result is a date prior to 1970, the date
will be January 1 1970 00:00:00.

ToGMTString()

Converts a date object to a string representation using the
local platform's GMT conventions.

ToLocale-String()

Converts a date object to a string representation using the
local platform's locale conventions. You should not use the resulting
string to pass a date, as the representation is highly platform-dependent.

Date.UTC (year, month, day, hour, minute, second)

Converts the specified date into the number of milliseconds
between the specified date and January 1, 1970, 00:00:00.000. The hour,
minute, and second parameters are optional and default to 0.

The document object contains information about the currently displayed
document. Its properties are derived from the document's BODY element:

<BODY>document contents</BODY>

The document object has 13 properties:

alinkColor

A string representing the color of an active link. It has
the value of BODY tag's ALINK attribute. You cannot change this property
after the document has been displayed.

anchors

An array, in source order, of named A tags.

bgColor

A string representing the color of the background. It
initially has the value of the BODY tag's BGCOLOR attribute. You can
change this property at any time.

cookie

The string representation of an element of the cookie.txt
file. You can change this property at any time.

fgColor

A string representing the color of the text. It has the
value of the BODY tag's TEXT attribute. You cannot change this property
after the document has been displayed.

forms

An array of references to the form objects in the document.
The form objects are in source order.

LastModified

A string representing the document's last modification date.
JavaScript formats the date for local time. Not all servers make this
information available to the browser; in such cases, this property will
represent a date of 1 January 1970 00:00:00 GMT, converted to local time.
You cannot modify this property.

linkColor

A string representing the color of unvisited links. It has
the value of the BODY tag's LINK attribute. You cannot change this
property after the document has been displayed.

links

An array of references to the link objects in the document.
The link objects are in source order.

location

A string that represents the document's URL. It is not
the same as the window's location object. You cannot change location.

referrer

A string that represents the URL of the calling document of
this document. You cannot change this property.

title

A string that represents the contents of the document's
TITLE tag. If a document has no TITLE tag or if the browser does not
display its TITLE element contents (that is, the document is in a
frame), this property is null. You cannot change this property.

vlinkColor

A string representing the color of a visited link. It has
the value of the BODY tag's VLINK attribute. You cannot change this
property after the document has been displayed.

The document object has five properties:

clear()

Clears the document in a window.

close()

Closes an output stream opened by open(). close() forces the
stream contents to display if the stream was open for layout.

open() open (mimeType)

Opens a stream to collect the output of the write() and
writeln() methods. open() clears the target window. If mimeType is
a text or image type, the stream is open for layout. mimeType is
one of the following:

The elements array contains references to input elements in a form. You
cannot add elements to this array, replace elements in the array, or remove
elements from the array. The elements array is a form object property. The
elements array has one property:

length

The number of entries in the elements array. You cannot
change this property.

A form object collects input from the user and may send the input to a
server. It is a reflection of a FORM element:

<FORM>form contents</FORM>

Each form object is a member of the containing document object's forms array.

A form object has six properties:

action

The FORM tag's ACTION attribute. You can change this
property at any time.

Elements

An array of the form object's input elements in source
order. Each radio button is a separate form element and a separate entry
in the array.

Encoding

The FORM tag's ENCTYPE attribute. You can change this
property at any time.

Length

The number of elements in the form object. You cannot change
this property.

Method

The FORM tag's METHOD attribute. You can change it at any
time.

Target

The FORM tag's TARGET attribute. This is the name of the
window that displays the response after the user submits formName. You can
change it at any time.

The form object has one method:

submit()

Submits the form's data to the server.

The form object has one event handler:

onSubmit

Executed when the user clicks on the form's SUBMIT button.
If the event handler returns false, JavaScript does not send the form's
data to the server. If the event handler returns true or fails to execute
a return statement, JavaScript sends the form's data to the server.

The forms array is a property of the containing document object. It contains
references to all of the form objects in the document, in source order. You
cannot add a form to the array, replace a form in the array, or remove a form
from the array.

The forms array has one property:

length

The number of entries in the forms array. You cannot change
this property.

The history object contains information on URLs that the user has visited in
a window and provides methods to revisit those URLs. The URLs themselves are not
visible to you, and you cannot add URLs to a history object or take URLs away
from a history object. The history object has one property:

length

The number of entries in the history object. You cannot
modify the length property.

The history object has three methods:

back()

Loads the previous URL in the history list. Performs the
same action as selecting the Back button in the navigator.

Forward()

Loads the next URL in the history list. Performs the same
action as selecting the Forward button in the navigator.

go(arg)

Loads the specified URL in the history list. If arg
is an integer, it is an index into the history list, with positive values
indexing forward into the list and negative values indexing backward into
the list. history.go(-1) is equivalent to history.back() and history.go(1)
is equivalent to history.forward(). history.go(0) forces the browser to
reload the current URL. If arg is a string, the browser loads the
nearest URL in the history list that has arg as a substring.
The comparison is case-insensitive.

A link object is a reflection of an A element that has an HREF attribute:

<A HREF=url>anchorText</A>

All links are members of the document's links array in source order.

URLs specify the location of documents on the Internet, and the protocol that
is used to retrieve them. The general format of a URL is

protocol hostname port pathname search hash

These are defined as follows:

protocol

The beginning of a URL, up to the first colon. Common
protocols include javascript: (JavaScript code), about: (navigator
information), http: (World Wide Web), file: (local file), ftp: (ftp),
mailto: (mail), news: (Usenet news), and gopher: (gopher). The protocol
may be separated from the rest of the URL by two slashes (http:, ftp:,
news:), three slashes (file:), or no slashes (javascript:, about:,
mailto:, gopher:).

Hostname

The host and domain name, or IP address, of a network host.

Port

The number of the communications port used by the network
host for communication. Many protocols define a "well-known" port number
(21 for ftp, 70 for gopher, 80 for the World Wide Web, 119 for Usenet
news, to name a few) for the protocol, and because most hosts use the
well-known port numbers, the port component is rarely used.

Pathname

The path of the file, including the file name, on the
network host.

Search

Query information, beginning with a question mark.

Hash

An anchor name, beginning with a hash mark (#)

A link object has nine properties:

hash

The hash component of the A element's HREF attribute.

host

The hostname and port components of the A
element's HREF attribute. The strings are separated by a colon. If there
is no port component, this property is the hostname component of
the A element's HREF attribute.

hostname

The hostname portion of the A element's HREF
attribute.

href

The entire HREF attribute of the A element. You can change
this property at any time.

pathname

The pathname component of the A element's HREF
attribute.

port

The port component of the A element's HREF attribute.

protocol

The protocol component of the A element's HREF
attribute.

search

The search component of the A element's HREF
attribute.

target

The A element's TARGET attribute. This is the name of the
window or frame that displays the document when the browser loads the
document. You can change it at any time.

The link object has two event handlers:

onClick

Executed when the user clicks on the display object.

OnMouseOver

Executed when the mouse pointer moves over the display
object from outside the object. The onMouseOver event handler must return
true if it wants to set the window's status or defaultStatus properties.

The links array contains references to all of the links in the document, in
source order. You cannot remove a link from the array or replace a link in the
array. You can create another link with the string object's link() method.

The links array has one property:

length

The number of entries in the links array. You cannot change
this property.

The location object contains information about a window object's Uniform
Resource Locator (URL). It has no methods or event handlers, and its properties
consist of the URL and its components. You can change a window object's
location, effectively forcing the window to be reloaded from a new URL. Although
you can reload a window by changing part of its URL, you should change the
entire URL by loading a new URL string into the href property instead.

The location object has eight properties:

hash

The hash component of the window's URL.

host

The hostname component of the window's URL, plus the
port component. The hostname and port components are
separated by a colon. If there is no port component, this is simply
the hostname component.

The navigator object refers to the browser itself, and it has properties that
you can use to tailor your JavaScript to the browser. There are limitations and
bugs associated with the Netscape Navigator that are specific to the platform it
is running on or to specific versions of the browser. The navigator object lets
you steer around these problems.

The navigator object has no methods and no event handlers. You cannot modify
any of its four properties:

appCodeName

The code name of the browser.

appName

The name of the browser.

appVersion

A string that represents version information about the
browser. The information format is version (platform;
country) where version is the browser version, platform
indicates the platform (Windows, UNIX, and so on), and country is I
(international version) or U (domestic United States release).

UserAgent

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

The options array is a property of select objects. It allows you to
manipulate the options of the select object. Individual options objects are
reflections of OPTION elements:

<OPTION>, text to be displayed

The options array has eight properties:

defaultSelected

The default selection state of an option object. It
initially has the value of the OPTION tag's SELECTED attribute. You can
change defaultSelected at any time. Doing so has no effect on the
appearance of the OPTION element.

index

The index of an option object in the options array. You
cannot change this property.

length

The number of entries in the options array. You cannot
change this property.

name

The SELECT element's NAME attribute. All OPTION elements are
supposed to be contained in a SELECT element. You can change this property
at any time.

selected

A Boolean value that indicates an option object's current
selection state. It is true if the option object is selected, and
false if it is not selected. You can change this property at any time.
Changing this property affects the appearance of the SELECT element
immediately.

selectedIndex

The index of the first selected option in the options array;
-1 if no option is selected. You can change this property at any time;
doing so clears all other options in the options array.

text

The text that follows an option object's OPTION tag. You can
change this property, but the display does not reflect the change.

value

The OPTION tag's VALUE attribute. You can change this
property, but the display does not reflect the change. JavaScript returns
this property to the server if the user selects the option.

A password object is a reflection of an INPUT element with a TYPE attribute
of "password":

<INPUT TYPE="password">

The data entered by the user is not visible to the display-each character
appears as an asterisk-and it is not visible programatically.

password objects are members of the containing form object's elements array.

A password object has three properties:

defaultValue

The default value for the password object. It is null
initially. You may change it at any time. Changing this property has no
effect on the display.

name

The INPUT tag's NAME attribute. You can change it at any
time.

value

The INPUT tag's VALUE attribute. You can change it at any
time. Changing this property immediately updates the display, but the
display shows it as a string of asterisks. If you set this property, you
can read it back, but if the user enters text into the input field, you
cannot read it.

A password object has three methods:

blur()

Removes focus from the password object.

focus()

Moves focus to the password object. When the password object
has focus, you can enter a value from JavaScript or the user can enter a
value.

select()

Highlights the input area of the input field and positions
the cursor for user response.

The radio object represents a set of INPUT elements of TYPE "radio" with the
same NAME attribute:

<INPUT TYPE="radio" NAME=radioName>

Each button in a radio object is a member of the containing form object's
elements array.

A radio object has five properties:

checked

A Boolean value that indicates whether a specific button in
the set of radio buttons is checked. You can change this property at any
time. Changing it changes the appearance of the buttons immediately.

defaultChecked

A Boolean value that indicates the default state of a
specific button in the set of radio buttons. The default state of the
button is checked if this property is true. The initial value of this
property is the CHECKED attribute of the INPUT tag. You can change this
property at any time. Changing it has no effect on the appearance of
the buttons.

length

The number of radio buttons in the radio object.
You cannot change this property.

name

The text following a specific button's INPUT tag.
You can change it at any time.

value

A specific radio button's INPUT tag's VALUE attribute. In
the absence of such an attribute, this property is set to "on".
JavaScript returns this property to the server if the user selected this
specific radio button. The browser does not display this property. You can
change this property at any time.

A radio object has one method:

click()

Selects the specified radio button. The onClick event
handler is not executed.

A string object is a series of characters. You can extract characters in a
string, and you can extract pieces of a string, which are called substrings. The
string object behaves like a sequence of characters ordered from left to right.

A string object has one property:

length

The number of characters in the string object. You cannot
change this property.

A string object has 19 methods:

anchor(name)

Creates an a document.write() or document.writeln(). The
string object contains the text the user will see. name is the anchor
element's NAME attribute. An anchor object created with this method
becomes a member of the anchors array.

big()

Formats the string object as if it were within a BIG
element.

blink()

Formats the string object as if it were within a BLINK
element.

bold()

Formats the string object as if it were within a B element.

charAt(index)

Returns the character at index into the string
object. If index is out of range, charAt() returns an empty string.

fixed()

Formats a string object as if it were within a TT element.

fontcolor(color)

Formats a string object as if it were within a FONT element
with the COLOR attribute set to color.

Fontsize(size)

Formats a string object as if it were within a FONT element
with the SIZE attribute set to size.

indexOf (searchText)

indexOf (searchText, index)

Searches a string object for an occurrence of
searchText, starting at index. If you omit index, the
browser assumes a starting index of 0. Returns the index where it finds
searchText. If it does not find searchText, it returns -1.

italics()

Formats a string object as if it were within an I element.

lastIndexOf (searchText) lastIndexOf (searchText,
index)

Searches the string object backwards for an occurrence of
searchText, starting at index. If you omit index, the browser
assumes a starting index of the string object's length minus 1. It returns
the index where it finds searchText. If it does not find
searchText, it returns -1.

link(href)

Creates an anchor element. The string object is the contents
of the element, and href is the value of the anchor element's HREF
attribute. A link created with this method becomes an element of the links
array.

small()

Formats a string object as if it were within a SMALL
element.

strike()

Formats a string object as if it were within a STRIKE
element.

sub()

Formats a string object as if it were within a SUB element.

Substring (index1, index2)

Returns a part of text defined by index1 and
index2. If index1 is less than index2, substring() returns the
characters in the string object index1 to index2 - 1. If
index2 is less than index1, substring() returns the characters in
text from index2 to index1 - 1. If index1 and
index2 are equal, substring() returns an empty string.

The window object is a top-level object that contains a document object, a
history object, and a location object. It may also contain a frames array, which
is an array of frame objects. The term "window" is somewhat ambiguous. It refers
to the entire browser display on the user's screen. The browser can spawn
additional displays; those displays are also windows. Each FRAMESET and FRAME
element also defines a window.

The browser display window has several components to which the window
object's properties and methods refer. One component, the status bar, has two
values that you can manipulate: a default message that normally appears, and a
transitory message that overrides the default message.

The window object has eight properties:

defaultStatus

The message that appears in the window status bar when
nothing else is in the status bar. If you change this property within an
onMouseOver event handler, the event handler must return true for
defaultStatus to be changed.

length

The number of frames. You cannot change this property.

name

The window's name.

parent

A synonym for the window or frame object that contains this
window object. You cannot change this property.

self

A synonym for this window object. You cannot change this
property.

status

The transitory message that appears in the window status
bar-for example, when a mouseOver event occurs. If you change this
property within an onMouseOver event handler, the event handler must
return true for status to be changed.

top

A synonym for the topmost window that contains frames or
nested framesets. You cannot change this property.

window

A synonym for the this window object. You cannot change this
property.

The window object has seven methods:

alert(message)

Displays message in a dialog box that requires no
user decision.

ClearTimeout (timeoutID)

Cancels the timeout specified by timeoutID.

close()

Closes the window. In event handlers, you must specify a
window reference (windowRef.close()). If you do not specify a window
reference, the browser assumes you meant document.close().

confirm (message)

Displays message in a dialog box that requires the
user to select either OK or Cancel. Returns true if the user selects
OK and false if the user selects Cancel.

open(URL, windowName, features)

Creates a new browser display window. URL is the URL to open
in the new window. windowName is a name that a FORM or A element
can use in its TARGET attribute. features is a column-delimited
list of window options. Do not use spaces. The options are
directories-Creates the standard Navigator directory buttons, if
true.

height=pixels-Specifies the window height in pixels. pixels must
be a positive number.

Location-Creates a location entry field, if true.

Menubar-Creates the menu at the top of the window, if true.

Resizable-Allows the user to resize the window, if true.

Scrollbars-Creates horizontal and vertical scrollbars when the
document is larger than the window, if true.

status-Creates the status bar at the bottom of the window, if
true.

toolbar-Creates the standard Navigator toolbar, if true.

width=pixels-Specifies the window width in pixels. pixels must
be a positive number.

The Boolean options (all options except height and width) are true if
included as option, option=1, or option=yes. Boolean
options are false if omitted or if included as option=0 or
option=no. Exception: if you list no window options and you omit
windowName, all options are true.

open() returns a window object reference.

prompt (message)

prompt (message, inputDefault)

Displays a dialog box that displays message and receives
user input. InputDefault is the default value. If you do not
specify inputDefault, the browser displays the
value <undefined>. prompt returns the text entered by the
user.

SetTimeout (expression, time)

Evaluates expression after time milliseconds.
setTimeout returns a timer ID that can be used in a call to
clearTimeout().

The window object can have two event handlers:

onLoad

Executed when a window or all frames in a frameset have
finished loading.

JavaScript provides six built-in functions. These functions are unrelated to
the built-in objects.

escape (string)

string is a string in the ISO Latin-1 character set.

Returns a string. escape() converts nonalphanumeric
characters in string to the form %xx, where xx is the hexadecimal
representation of the character's value. escape() passes alphanumeric
characters in string to the return string intact.

eval (string)

string is a string containing a JavaScript statement
or expression or sequence of statements.

Evaluates string and returns a value.

isNan (value)

value is a value returned from parseFloat() or
parseInt().

Returns true if value is NaN. NaN is a special value
returned by parseFloat() and parseInt() to indicate that the evaluated
value is not a number. parseFloat() and parseInt() do not return NaN in
Windows platforms.

parseFloat (string)

string is a string representing a numric value.

Returns the floating-point number that string
represents. It stops parsing string when it encounters a character
that is not part of a valid numeric expression. parseFloat() returns NaN
(not a number), under all platforms except Windows, if it cannot create a
valid floating-point number. parseFloat() returns 0 under Windows when it
cannot create a valid floating-point number.

parseInt (string) or parseInt (string, radix)

string is a string representing a numeric value.
radix is a nonnegative integer.

Returns the integer that string, in the specified
radix, represents. The browser guesses a radix if you omit
radix or specify a value of 0. The browser assumes a value of 16 if
string begins with 0x, 8 if string begins with 0, and 10 if
string begins with any other digit. JavaScript assumes that letters
are digits, such as A-F for a radix of 16, when radix is greater
than 10. parseInt() returns NaN (not a number), under all platforms except
Windows, if it cannot create a valid floating-point number. ParseInt()
returns 0 under Windows when it cannot create a valid floating-point
number.

Unescape (string)

string is a string that contains sequences of
"%number", where number is a value from 0 to 255, or "0xnumber",
where number is a hexadecimal value from 00 to FF.

Returns a string with the escaped values in string
converted to ISO Latin-1 characters.