21.3 The JavaScript Reference
Pages
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.
Anchor Object
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>
Array Object
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
Properties
-
length
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).
Methods
-
join
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
Reverse, in place (i.e., without creating a new array),
the order of the elements of an array.
-
sort
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:
-
Return a value less than zero if, according to your sort criteria,
a
is less than b, and should appear before b in the sorted
array.
-
Return zero if a and b are equivalent for the purposes of
this sort.
-
Return a value greater than zero if a is greater than b for
the purposes of the sort.
Boolean Object
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:
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.
Methods
-
toString()
Returns true or false, depending on
the boolean value represented by the Boolean object.
-
valueOf()
Returns the boolean value represented by the Boolean
object.
Button 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']
Properties
-
form
Read-only reference to the Form object that contains
the specified
button object.
-
name
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']
-
type
See the type property of the Element object (Element.type).
-
value
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.
Event Handlers
-
onClick()
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
HTML syntax
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>
Checkbox Object
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
Properties
-
checked
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.
-
defaultChecked
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.
-
form
Read-only reference to the Form object that contains
the Checkbox.
-
name
Read-only string, set by the HTML name attribute,
that specifies the name of the Checkbox object (or array of Checkbox objects).
-
type
See the type property of the Element object (Element.type).
-
value
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."
Event handlers
-
onclick()
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
HTML syntax
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>
Date Object
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
Methods
-
getDate()
Returns the day of the month of a Date object. Return
values are between 1 and 31.
-
getDay()
Returns the day of the week of a Date object. Return
values are between 0 (Sunday) and 6 (Saturday).
-
getHours()
Returns the hours field of a Date object. Return values
are between 0 (midnight) and 23 (11 PM).
-
getMinutes()
Returns the minutes field of a Date object. Return values
are between 0 and 59.
-
getMonth()
Returns the month field of a Date object. Return values
are between 0 (January) and 11 (December).
-
getSeconds()
Returns the seconds field of a Date object. Return values
are between 0 and 59.
-
getTime()
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).
-
getTimezoneOffset()
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.
-
getYear()
Returns the year field of a Date object. Return value
is the year minus 1900 (e.g., 96 for 1996).
-
parse()
Parses a string representation of a date and returns
it in millisecond format.
-
setDate()
Sets the day of the month field of a Date object.
date.setDate(day_of_month) // day_of_month is 1-31
-
setHours()
Sets the hour field of a Date object.
date.setHours(hours) //hours is integer betw 0
(midnight) and 23 (11pm)
-
setMinutes()
Sets the minutes field of a Date object.
date.setMinutes(minutes) //minutes is integer betw 0 and 59
-
setMonth()
Sets the month field of a Date object.
date.setMonth(month) //month is integer betw 0 (Jan) and 11 (Dec)
-
setSeconds()
Sets the seconds field of a Date object.
date.setSeconds(seconds) //seconds is integer betw 0 and 59
-
setTime()
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)
-
setYear()
Sets the year field of a Date object.
date.setYear(year) // year is year minus 1900; e.g. 96 for 1996
-
toGMTString()
Converts a Date to a string, using the GMT time zone;
format of string varies slightly according to platform.
-
toLocaleString()
Converts a Date to a string, using the local time zone;
uses local conventions for data and time formatting.
-
UTC()
Converts a numeric date and time specification to millisecond
format.
Date.parse( ) Method
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.UTC( ) Method
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));
Document Object
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
Properties
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).
-
alinkColor
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>.
-
anchors[]
An array of Anchor objects, one for each anchor (i.e.,
hypertext target) in the document.
-
anchors.length
Read-only integer specifying the number of elements in
the
anchors[] array.
-
applets[]
An array of Java objects, one for each <applet>
that appears in the document.
-
applets.length
A read-only integer specifying the number of elements
in the
applets[] array.
-
bgColor
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.
-
cookie
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.
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:
date should be a date specification in the format
written by Date.toGMTString().
-
domain
String that specifies the Internet domain which the document
is from; used for security purposes.
-
embeds[]
An array of Java objects, one for each <embed>
tag that appears in the document.
-
embeds.length
Read-only integer that specifies the number of elements
in the embeds[] array.
-
fgColor
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>.
-
forms[]
An array of Form objects, one for each <form>
that appears in the document.
-
forms.length
Read-only integer specifying the number of elements in
the
forms[] array.
-
images[]
An array of Image objects, one for each image embedded
in the document with the <img> tag.
-
images.length
The number of elements in the images[] array.
-
lastModified
Read-only string that contains the (local) date and time
at which
document was most recently modified (derived from the HTTP
header).
-
linkColor
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>.
-
links[]
An array of Link objects, one for each hypertext link
in the document.
-
links.length
Read-only integer specifying the number of elements in
the links[] array.
-
location
Synonym for the URL property. Use URL
instead because it is less likely to be confused with the Window.location
property.
-
plugins[]
Synonym for the embeds[] array.
-
plugins.length
The number of elements in the plugins[] or embeds[]
array.
-
referrer
Read-only string that contains the URL of the document
from which the current document was reached.
-
title
Read-only string that specifies the <title>
of the document.
-
URL
Read-only string that specifies the URL of the document
that contained the link that referred to the current document.
-
vlinkColor
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>.
Methods
-
clear()
Clears the window or frame that contains document.
-
close()
Displays any output to document that has been
written but not yet displayed, and closes the output stream.
-
open()
Opens a stream to document, so that subsequent
document.write()
calls can append data to the document.
-
write()
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().
-
writeln()
Identical to write(), except that it appends
a newline character to the output.
Event handlers
The following event handlers are, strictly speaking,
properties of Window, not Document:
-
onload
Invoked when the document is fully loaded. Specified
by the onLoad attribute of
<body>.
-
onUnload
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>
Element Object
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
Properties
-
form
Read-only reference to Form object that contains this
element.
-
name
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.
-
type
Read-only string property (Netscape 3.0 and later) that
specifies the type of the form element. The value depends on the input
element:
-
value
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.
escape( ) Function
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:
yields the string:
eval( ) Function
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.
FileUpload Object
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']
Properties
-
form
Read-only reference to the Form object that contains
the FileUpload object.
-
name
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.)
-
type
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.
-
value
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.
Methods
-
blur()
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.
-
focus()
Sets the keyboard focus to the FileUpload object. When
focus is set, all keystrokes are automatically entered into this object.
Event handlers
-
onblur()
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.
-
onchange()
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.
-
onfocus()
Invoked when a user action causes the FileUpload object
to gain the keyboard focus.
HTML syntax
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
...
Form Object
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
Properties
-
action
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.
-
elements[]
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.
-
elements.length
The number of items in the elements[] array.
-
encoding
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.
-
method
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.
-
target
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.
Methods
-
reset()
Resets each of the input elements of the form to their
default values.
-
submit()
Method that submits a form.
Event Handlers
-
onreset
Invoked just before the elements of the form are reset.
Specified by the onReset attribute.
-
onsubmit
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.
HTML syntax
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>
Frame Object
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:
-
When the defaultStatus property is set for a frame, the specified
status message is only visible when the mouse is within that frame.
-
The top and parent properties of a top-level browser
window always refer to the top-level window itself. These properties are
only really useful for frames.
-
The close() method is not useful for Window objects that are frames.
Available in Netscape 2.0.
window.frames[i]
window.frames.length
frames[i]
frames.length
Function Object
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.
Properties
-
arguments[]
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.
-
arguments.length
The number of elements in the arguments[] array.
-
caller
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.
-
prototype
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.
Methods
-
toString()
Converts the Function object to a string by returning
the function definition (a string of valid JavaScript code).
-
valueOf()
Returns the function value contained in a Function object.
See the Object.valueOf() method.
getClass( ) Function
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.
Usage
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:
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:
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)
Hidden Object
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']
Properties
-
form
Read-only reference to the Form object that contains
the Hidden object.
-
name
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.
-
type
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.
-
value
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.
HTML syntax
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>
History Object
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
Properties
-
current
Read-only string that specifies the URL of the current
document. Only available with data tainting enabled in Netscape 3.0.
-
length
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.)
-
next
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.
-
previous
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.
Methods
-
back()
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:
-
forward()
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:
-
go()
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.
-
toString()
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.
Image Object
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]);
Properties
-
border
Read-only integer that specifies the width, in pixels,
of the border around an image. Its value is set by the
border
attribute.
-
complete
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.
-
height
Read-only integer that specifies the height, in pixels,
of the image. Its value is set by the height attribute.
-
hspace
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.
-
lowsrc
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.
-
name
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.
-
src
Read/write string that specifies the URL of the image
to be displayed. Its initial value is set by the src attribute.
-
vspace
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.
-
width
Read-only integer that specifies the width, in pixels,
of the image. Its value is set by the width attribute.
Event handlers
-
onabort
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
-
onerror
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
-
onload
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
HTML syntax
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
>
isNaN( ) Function
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.
JavaArray Object
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
Properties
-
length
Read-only integer that specifies the number of elements
in the Java array represented by the JavaArray object.
Usage
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);
JavaClass Object
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
Usage
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();
JavaObject Object
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
Usage
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;
JavaPackage Object
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
Properties
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.
Usage
You can use JavaPackage objects to refer to any Java
class. The java.lang.System class, for example, is:
Or:
Packages.java.lang.System
Similarly, the netscape.javascript.JSObject class
is:
Packagestscape.javascript.JSObject
Link Object
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
Properties
-
hash
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.
-
host
The combination of the hostname and port portions of
the HREF URL.
-
hostname
The hostname portion of the HREF URL.
-
href
The complete URL specified by the HREF property.
-
pathname
The path portion of the HREF URL.
-
port
The port portion of the HREF URL.
-
protocol
The protocol portion of the HREF URL, including
the trailing colon.
-
search
The search or query portion of the HREF URL,
including the leading question mark.
-
target
The name of a Window object (i.e., a frame or a toplevel
browser window) in which the HREF URL should be displayed.
Event handlers
The values of the following attributes may be any number
of JavaScript statements separated by semicolons.
-
onclick()
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
-
onmouseout()
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
-
onmouseover()
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
HTML syntax
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>
Location Object
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[]
Properties
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
-
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
-
host
A combination of the hostname and port portions of the
URL.
location.host
window.location.host
document.links[i].host
-
hostname
The hostname portion of the URL.
location.hostname
window.location.hostname
document.links[i].hostname
-
href
The complete URL.
location.href
window.location.href
document.links[i].href
-
pathname
The path portion of the URL.
location.pathname
window.location.pathname
document.links[i].pathname
-
port
The port portion of the URL.
location.port
window.location.port
document.links[i].port
-
protocol
The protocol portion of the URL, including the trailing
colon.
location.protocol
window.location.protocol
document.links[i].protocol
-
search
The search or query portion of the URL, including the
leading question mark.
location.search
window.location.search
document.links[i].search
Methods
-
reload()
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)
-
replace()
Replaces the current document with a new one, without
generating a new entry in the browser's session history.
Math Object
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;
-
Constants
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
-
Methods (Functions)
-
abs
Computes an absolute value.
Math.abs(x) // x is any numeric value or expression
-
acos
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
-
asin
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
-
atan
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
-
atan2
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
-
ceil
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
-
cos
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
-
exp
Computes an exponent of $e$.
Math.exp(x) // x is a number or numeric expression
to be used as exponent
-
floor
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
-
log
Computes a natural logarithm.
Math.log(x) // x is any numeric value or expression greater than 0
-
max
Returns the larger of two values.
Math.max(a, b) // a, b are any two numeric values or expressions
-
min
Returns the smaller of two values.
Math.min(a, b) // a, b are any two numeric values or expressions
-
pow
Computes $x sup y$. (Raises its first argument to the
power of its second argument and returns the result.)
-
random
Computes a random number; available in 3.0 and later.
-
round
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
-
sin
Computes a sine.
Math.sin(x) // x is an angle, in radians
-
sqrt
Computes a squareroot.
Math.sqrt(x) // x is any numeric value or expression
greater than or
equal to 0
-
tan
Computes a tangent.
Math.atan(x) // x is an angle, in radians
MimeType Object
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
Properties
-
description
Read-only English description of the content and encoding
of the type.
-
enabledPlugin
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.
-
name
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.
-
suffixes
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").
Usage
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);
Navigator Object
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.
Properties
-
appCodeName
Read-only string specifying the code name of the browser.
-
appName
Read-only string specifying the name of the browser.
-
appVersion
Read-only string specifying version information for the
browser.
-
mimeTypes[]
An array of MimeType objects describing the MIME types
recognized and supported by the browser. Added in Netscape 3.0.
-
mimeTypes.length
The number of elements in the mimeTypes[] array.
-
plugins[]
An array of Plugin objects describing the installed plugins.
Added in Netscape 3.0.
-
plugins.length
The number of elements in the plugins[] array.
-
userAgent
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)".