JavaScript Pocket Reference - Flanagan, David
JavaScript Pocket Reference - Flanagan, David
Pocket Reference
David Flanagan
OREILLY*
Beijing Cambridge Koln Paris Sebastopol Taipei Tokyo
JavaScript Pocket Reference
by David Flanagan
Printing History:
October 1998: First Edition
@
Thisbook is printed on acid-free paper with 85% recycled content,
15% post-consumer waste. O'Reilly & Associates is committed to
using paper with the highest recycled content available consistent
with high quality.
Versions of JavaScript 1
JavaScript Syntax 1
Variables 3
Data Types 4
Statements 11
Regular Expressions 16
JavaScript in HTML 17
Forms 20
Events 21
Global Properties 24
Global Functions 24
Versions ofJavaScript
The following table specifies what versions of client-side
JavaScript are supported by various versions of Netscape
Navigator and Microsoft Internet Explorer:
2 JavaScript 1.0
JavaScript Syntax
is modeled on Java syntax, Java syntax, in
JavaScript syntax
turn, modeled on C and C++ syntax. Therefore, C, C++,
is
Case sensitivity
JavaScript is a case-sensitive language. All keywords are
in lowercase. All variables, function names, and other
identifiers must be typed with a consistent capitalization.
Whitespace
JavaScript ignores whitespace between tokens. You may
use spaces, tabs, and newlines to format and indent your
code in a readable fashion.
Semicolons
JavaScript statements are terminated by semicolons. When
a statement is followed by a newline, however, the termi-
nating semicolon may be omitted. Note that this places a
restrictionon where you may legally break lines in your
JavaScript programs: you may not break a statement
across two lines if the first line can be a complete legal
statement on its own.
Comments
JavaScript supports both C and C++ comments. Any
amount of text, on one or more lines, between /* and */
is a comment, and is ignored by JavaScript. Also, any text
Identifiers
Variable, function, andlabel names are JavaScript identi-
fiers. Identifiers are composed of any number of ASCII let-
ters and and the underscore (_) and dollar sign ($)
digits,
characters. The
first character of an identifier must not be
my_variabl e_name
vl3
$str
var i ;
var j = 1+2+3;
var k, ,m,n 1 ;
Variables
:
Data Types
JavaScript supports three primitive data types: numbers,
boolean values, and strings. In addition, it supports two com-
pound data types: object and arrays. Functions are also a first
Numbers
Numbers in JavaScript are represented in 64-bit floating-
point format. JavaScript makes no distinction between
integers and floating-point numbers. Numeric literals
3.14
.0001
6.02e23
Booleans
The boolean type has two possible values, represented by
the JavaScript keywords true and fal se. These values
represent truth or falsehood, on or off, yes or no, or any-
thing else that can be represented with one bit of infor-
mation.
Strings
A JavaScript string is a sequence of arbitrary letters, digits,
testing '
"3.14"
'name="myform"
"Wouldn't you prefer O'Reilly's book?"
Escape Represents
\b Backspace
\f Form feed
\n Newline
\r Carriage return
\t Tab
V Apostrophe or single quote that does
not terminate the string
Data Types
Escape Represents
\" Double-quote that does not terminate
the string
\\ Single backslash character
\ddd Character with Latin- 1 encoding speci-
fied by three octal digits ddd
\xdd Character with Latin- 1 encoding speci-
fied by two hexadecimal digits dd
\udddd Character with Unicode encoding spec-
ified by four hexadecimal digits dddd
\n n, where n is any character other than
those shown above
Objects
An object is a compound num-
data type that contains any
ber of properties. Each property has a name and a value.
The . operator is used to access a named property of an
object. For example, you can read and write property val-
ues of an object o as follows:
o.x = 1
o.y = 2;
o. total = o.x + o.y;
o["x"] = 1;
o["y"] = 2;
Objects are created with the new operator. You can create
a new object with no properties as follows:
You can also define your own object classes and corre-
sponding constructors.
Arrays
An array is a type of object that contains numbered values
rather than named values. The [ ] operator is used to
access the numbered values of an array:
a[0] = 1;
a[l] = a[0] + a[0];
Data Types
;
var a = [1,2,3];
var b - [1, true, [1,2], {x:l, y:2}, "Hello"];
function sum(x, y) {
return x + y
}
1+2
total /n
sum(o.x, a [3])++
(l+2)*3
associativity.
L + String concatenation
L > t
>= Greater than, greater than or
equal
9 L == , !
= Test for equality or inequality
Statements
A JavaScript program is a sequence of JavaScript statements.
Expression statements
Every JavaScript expression can stand alone as a state-
ment. Assignments, method calls, increments, and decre-
ments are expression statements. For example:
s = "hel o world"1
x = Math.sqrt(4) ;
x++
Compound statements
When a sequence of JavaScript statements is enclosed
within curly braces, it counts as a single compound state-
ment. For example, the body of a whi 1 e loop consists of
a single statement. If you want the loop to execute more
than one statement, use a compound statement. This is a
common technique with if, f or , and other statements
described later.
Empty statements
The empty statement is simply a semicolon by itself. It
does nothing, and is occasionally useful for coding empty
loop bodies.
Labeled statements
In JavaScript 1.2, any statement can be labeled with a
name. Labeled loops can then be used with the labeled
versions of the break and continue statements:
]abe] : statement
Statements 11
e :
break
The break statement terminates execution of the inner-
most enclosing loop, or, in JavaScript 1.2, the named loop:
break ;
case
case is not a true statement. Instead it is a keyword
used to label statements within a JavaScript 1.2 switch
statement:
case constant-express/or? :
statements
[ break ] ;
continue
The continue statement restarts the innermost enclosing
loop, or, in JavaScript 1.2, restarts the named loop:
continue ;
defaul t
statements
[ break ] ;
ao/whi 1
export
The export statement was introduced in Navigator 4. It
makes the specified functions and properties accessible to
other windows or execution contexts:
for
The for statement is an easy-to-use loop that combines
the initialization and increment expressions with the loop
condition expression:
for/i n
function
The function statement defines a function in a JavaScript
program:
Statements 13
4
function funcname(args) {
statements
>
if/el se
The i f statement executes a statement if an expression is
true:
if ( expression )
statement
if ( expression )
statement
el se
statementZ
if expression
( )
statement
else if expression2
( )
statementZ
el se
statements
import
The import statement was introduced in Navigator 4
along with export It makes the named functions and
.
return
The return statement causes the currently executing
function to stop executing and return to its caller. If fol-
lowed by an expression, the value of that expression is
used as the function return value.
return ;
return expression ;
switch
The switch statement is a multi-way branch. It evaluates
an expression and then jumps to a statement that is
labeled with a case clause that matches the value of the
expression.If no matching case label is found, the
switch expression { ( )
[ . . . ]
defaul t : statements
}
var
The var statement declares and optionally initializes one
or more variables. Variable declaration is optional in top-
level code, but is required to declare local variables within
function bodies:
while expression ( )
statement ;
with
The with statement adds an object to the scope chain, so
that a statement is interpreted in the context of the object:
Statements 15
with ( object )
statement ;
Regular Expressions
JavaScript 1.2 supports regular expressions, using the same
syntax as Perl 4. A regular expression is specified literally as
a sequence of characters within forward slashes (/), or as a
JavaScript string passed to the RegExpO constructor. The
optional g (global search) and i (case-insensitive search)
modifiers may follow the second / character, or may be
passed to RegExpO.
Character Meaning
\n, \r,\t Match literal newline, carriage return, tab
w, \/, v*, Match a special character literally, ignoring
\H -, \?, etc. or escaping its special meaning
matched
\n Match exactly the same characters that
were matched by sub-expression number
n
JavaScript in HTML
Client-side JavaScript code may be embedded in HTML files
in several ways:
<SCRIPT> tag
Most JavaScript code appears in HTML files between a
<SCRIPT> tag and a </SCRIPT> tag. The <SCRIPT> tag
can also be used to include an external file of JavaScript
code into an HTML document. The <SCRI PT> tag sup-
ports a number of attributes, including these three impor-
tant ones:
LANGUAGE
Specifies the scripting language in which the script is
written. In most browsers, this attribute defaults to
"JavaScript". You must set it if you are mixing
scripting languages, such as JavaScript and VBScript.
JavaScript in HTML 17
however, that Navigator 4 has some non-standard
behaviors when "JavaScript 1.2" is specified.)
SRC
Specifies the URL of an external script to be loaded and
executed. Files of JavaScript code typically have a js
extension. Note that the </SCRI PT> tag is still required
when this attribute is used. Supported in JavaScript 1.1
and later.
ARCHIVE
Specifies the URL of a JAR file that contains the script
specified by the SRC attribute. Supported in JavaScript
1.2 and later. Archives are required to use Navigator 4
signed scripts.
Event handlers
JavaScript code may also appear as the value of event
handler attributes of HTML tags. Event handler attributes
always begin with "on". The code specified by one of
these attributes is executed when the named event occurs.
For example, the following HTML specifies a button that
displays a dialog box when clicked:
JavaScript URLs
JavaScript code may appear in a URL that uses the special
javascript: pseudo-protocol. The JavaScript code is
evaluated, and the resulting value (converted to a string,
if necessary) is used as the contents of the URL. Use the
JavaScript entities
In JavaScript 1.1, HTML attribute values may contain Jav-
aScript code in the form of JavaScript entities. An HTML
entity is a string like & 1 1 ; that represents some other char-
self, window,
parent, top \
CB>
pluffinan
wtovsWmdo* objects ]
navigator
Navigator object * mimeTypes
way of MimeType objects
[]
frames [
array of Window objects forms [] elements []
Button
Location object anchors [
Checkbox
may of Anchor objects FUeUphad «H>
history Hidden
Password
Historyobjed links [}
Radio
may of Link objects itset options!]
Select
orrayof
€S> !
Document object
t images [
array of (mage objects
Submit
hxt
Jextarea
Optmohjects j
<B>
applets []
array of applets
<S>
embedsH
array of embedded objects
Forms
One of the powerful features of JavaScript is its ability to
Sefeef(<SELECT[MULTIPLE]>. .</SELECT>) .
Forms 21
,
Ad*ass|«JE avosc
Input Events[3]
Username: Password:
Change: browser (other)
[l]|david [2]h~- :: browser (other)
Focus hobbies
: ( )
Click: hobbies (
Change: hobbies (
programming )
Change: hobbies (
programming caffeine )
:: hobbies programmii (
caffeine )
Fonn Elements [1] Text [2] Password [3] Textarea [4} FileUpload [5] Checkbox !;
[6] Radio [7] Select (list) [8] Select (menu) [9] Button [10] Submit [11] Reset
Events
Client-side JavaScript supports a number of event types. The
following table lists the event handlers and the client-side
objects that support the handlers. Note that some events, such
as onDbl CI i ck , are not reliably generated on all platforms.
JavaScript
Security Restrictions
For security reasons, there are restrictions on the tasks that
untrusted JavaScript code can perform. In Navigator 4, signed
scripts can circumvent these restrictions by requesting certain
privileges:
File uploads
Scriptscannot set the value property of the FileUpload
form element without Universal BrowserRead.
Global Properties
Core JavaScript defines two global constants:
Infinity
A numeric constant that represents infinity. Internet
Explorer 4; ECMA-262; not supported by Navigator 4.
NaN
The not-a-number constant. Internet Explorer 4; ECMA-
262; not supported by Navigator 4.
eval {code)
Execute JavaScript code from a string.
getCl dss(javdobj)
Return the JavaClass of a JavaObject. Navigator 3.
i sFini te(n)
Determine whether a number is finite. JavaScript 1.2;
ECMA-262.
isNaN(x)
Check for not-a-number. JavaScript 1.1; ECMA-262.
parseFl oat(s)
Convert a string to a number. JavaScript 1.0; enhanced in
JavaScript 1.1; ECMA-262.
parselnt(s, radix)
Convert a string to an integer. JavaScript 1.0; enhanced in
JavaScript 1.1; ECMA-262.
unescape(s)
Decode an escaped string. JavaScript 1.0; ECMA-262;
Unicode support in Internet Explorer 4.
Global Functions 25
1
Anchor
Availability
Inherits From
HTMLElement
Synopsis
document. anchors[/]
document, anchors. length
Properties
name
The name of an anchor.
text
The text of an anchor. Navigator 4.
x
The X-coordinate of an anchor. Navigator 4.
y
The Y-coordinate of an anchor. Navigator 4.
Availability
Client-side JavaScript 1 .
Arguments
Synopsis
Properties
Methods
The methods of an Applet object are the same as the public
methods of the Java applet it represents.
Arguments
arguments and other properties of a function
Availability
Synopsis
arguments
Properties
cal 1 ee
The function that is currently running. JavaScript 1.2;
ECMA-262.
cal ler
The calling context. Navigator 4.
1 ength
The number of arguments passed to a function.
Array
Availability
Constructor
new Array( )
new Array(s7'ze)
new Array(e7 ementO, elementl, . . . , elementn)
Properties
1 ength
The size of an array. JavaScript 1.1, Internet Explorer 3;
ECMA-262.
Methods
concat( va ue, 1 . . . )
join(separator)
Concatenate array elements to form a string. JavaScript
1.1; ECMA-262.
pop(
Remove and return the last element of an array. Navigator
4.
push( va ue 1 , . . . )
reverse( )
shiftO
Shift array elements down. Navigator 4.
Button
si iceistart, end)
Return a portion of an array. JavaScript 1.2.
sort(orderfunc)
Sort the elements of an array. JavaScript 1.1; ECMA-262.
spl ceistart, del eteCount value, , . . . )
toString( )
Availability
Constructor
II Constructor function
new Bool ean( va ue)
II Conversion function
Bool ean( va ue) 1
Methods
toString( )
Availability
Inherits From
Input, HTMLElement
Checkbox
Synopsis
form, name
form, el ements[/]
Properties
val ue
The text that appears in a Button.
Methods
Button inherits methods from Input and HTMLElement.
Event Handlers
Button inherits event handlers from Input and HTMLElement
and also defines or overrides the following:
oncl i ck
The handler invoked when a Button is clicked.
Availability
Inherits From
Input, HTMLElement
Synopsis
Properties
defaul tChecked
The initial state of a Checkbox.
val ue
The value returned when a form is submitted.
Methods
Checkbox inherits the methods of Input and HTMLElement.
Event Handlers
Checkbox inherits event handlers from Input and HTMLEle-
ment and also defines or overrides the following:
oncl ick
The handler invoked when a Checkbox is selected.
Availability
Synopsis
crypto
Functions
crypto. random (numbytes)
Generate random byte strings.
Date
Availability
Constructor
new Date( )
new Date (077 iseconds) 7 7
new Ddte(ddtestring) ;
Methods
Note that unlike most JavaScript objects, the Date object has
no properties can be read and written directly; instead,
that
all access to date and time fields is done through methods:
getDateO
Return the day of the month. JavaScript 1.0; ECMA-262.
getDayO
Return the day of the week. JavaScript 1.0; ECMA-262.
getFullYearO
Return the year (local time). JavaScript 1.2; ECMA-262.
getHours( )
getMi 1 1 seconds( )
getMinutes( )
getMonth(
Return the month of a Date. JavaScript 1.0; ECMA-262.
Date
getSeconds(
Return the seconds field of a Date. JavaScript 1.0;
ECMA-262.
getTime( )
getUTCDayO
Return the day of the week (universal time). JavaScript
1.2; ECMA-262.
getUTCFullYearO
Return the year (universal time). JavaScript 1.2; ECMA-
262.
getUTCHoursO
Return the hours field of a Date (universal time).
JavaScript 1.2; ECMA-262.
getUTCMil 1 iseconds( )
getUTCMinutesO
Return the minutes field of a Date (universal time).
JavaScript 1.2; ECMA-262.
getUTCMonthO
Return the month of the year (universal time). JavaScript
1.2; ECMA-262.
getUTCSeconds(
Return the seconds field of a Date (universal time).
JavaScript 1.2; ECMA-262.
getYear( )
setHours(/?OL/rs)
Set the hours field of a Date. JavaScript 1.0; ECMA-262.
setMinutes(/777/7wtes)
Set the minutes field of a Date. JavaScript 1.0; ECMA-262.
setMonth(tf70/7t/?)
Set the month field of a Date. JavaScript 1.0; ECMA-262.
setSeconds(seco/7c/s)
Set the seconds field of a Date. JavaScript 1.0; ECMA-262.
setTime(/777 7 7 i seconds)
Set a Date in milliseconds. JavaScript 1.0; ECMA-262.
setUTCDate (day__of_month)
Set the day of the month (universal time). JavaScript 1.2;
ECMA-262.
setUTCFul 1 Year (year)
Set the year (universal time). JavaScript 1.2; ECMA-262.
setUTCHours(/70i/rs)
Set the hours field of a Date (universal time). JavaScript
1.2; ECMA-262.
setUTCMi 1 1 i seconds (/7? / 7 7 is)
Set the milliseconds field of a Date (universal time).
JavaScript 1.2; ECMA-262.
setUTCMi nutes(/W7/7wtes)
Set the minutes field of a Date (universal time). JavaScript
1.2; ECMA-262.
J
Date
setUTCMonth(/770/7t/7)
Set the month (universal time). JavaScript 1.2; ECMA-262.
setUTCSeconds( seconds)
Set the seconds field of a Date (universal time). JavaScript
1.2; ECMA-262.
setYear(year)
Set the year field of a Date. JavaScript 1.0; ECMA-262; dep-
recated in JavaScript 1.2 in favor ofsetFullYearO.
toGMTStringO
Convert a date to a universal time string. JavaScript 1.0;
toUTCStringO
Convert a date to a string (universal time). JavaScript 1.2;
ECMA-262.
valueOfO
Convert a date to a number. JavaScript 1.1; ECMA-262.
Static Methods
Date.parse(c/ate)
Parse a date/time string. JavaScript 1.0; ECMA-262.
Availability
Inherits From
HTMLElement
Synopsis
window, document
document
Properties
al inkCol or
The color of activated links.
anchors[]
The Anchors in a document. JavaScript 1.0; array elements
are null prior to JavaScript 1.2.
appl ets[]
The applets in a document. JavaScript 1.1.
bgCol or
The document background color.
cookie
The cookie(s) of the document.
domain
The security domain of a document. JavaScript 1.1.
embeds[]
The objects embedded in a document. JavaScript 1.1.
forms[]
The Forms in a document.
images[]
The images embedded in a document. JavaScript 1.1.
1 astModif ied
The modification date of a document.
1 inkCol or
The color of unfollowed links.
links[]
The Link objects in a document.
1 ocation
The URL of the current document. JavaScript 1.0; depre-
cated in JavaScript 1.1 in favor of Document URL. .
plugins[]
The objects embedded in a document. JavaScript 1.1.
referrer
The URL of the linked-from document. JavaScript 1.0;
title
The title of a document.
URL
The URL of the current document. JavaScript 1.1.
vl inkCol or
The color of visited links.
Navigator 4 Properties
cl asses
Define style classes.
height
The height of a document.
Document
ids
Define styles for individual tags.
layers[]
The layers contained in a document.
tags
Define styles for HTML tags.
width
The width of a document.
all[]
All HTML elements in a document.
charset
The character set in use.
chi ldren[]
The child elements of the document.
defaul tCharset
The default character set of a document.
expando
Disallow new property creation.
parentWindow
The window of a document.
readyState
The loading status of a document.
Methods
Document inherits methods from HTMLElement and also
defines some methods. Navigator 4 and IE 4 both define a
number of incompatible Document methods, used mostly for
DHTML; they are listed separately after the generic methods:
cl ear(
Clear a document. JavaScript 1.0; deprecated.
Document
cl ose(
Close an output stream.
oper\(mimetype)
Begin a new document.
writel n( va ue,1 . . .
Navigator 4 Methods
captureEvents( event mask)
Specify event types to be captured.
getSel ection(
Return the selected text.
rel easeEvents(ei/e/7t/7?as^)
Stop capturing events.
routeEvent(ei/er?t)
Pass a captured event to the next handler.
el ementFromPoi nt(x, y)
Determine which HTML element is at a given point.
Event Handlers
The <B0DY> tag has onLoad and onLlnl oad attributes. Tech-
however, the onload and onunl oad event handlers
nically,
belong to the Window object, rather than the Document
object.
Availability
Synopsis
Navigator 4 Properties
data
Data from a DragDrop event. Requires Universal -
1 ayerX
The X-coordinate, within a layer, of the event.
1 ayerY
The Y-coordinate, within a layer, of the event.
modi f iers
Which modifiers keys are held down.
pageX
The X-coordinate, within a page, of the event.
pageY
The Y-coordinate, within a page, of the event.
screenX
The screen X-coordinate of the event. JavaScript 1.2.
screenY
The screen Y-coordinate of the event. JavaScript 1.2.
Event
target
The object on which the event occurred.
type
The type of the event. JavaScript 1.2.
TYPE
Static event type constants for bitmasks.
which
Which key or mouse button was clicked.
width
The new width of a resized window or frame.
x
The X-coordinate of the event within a positioned ele-
ment. JavaScript 1.2.
y
The Y-coordinate of the event within a positioned ele-
ment. JavaScript 1.2.
altKey
Whether the ALT key was pressed during an event.
button
Which mouse button was pressed.
cancel Bubbl
Stop event propagation.
cl ientX
The X-coordinate, within a page, of the event.
cl ientY
The Y-coordinate, within a page, of the event.
Ctrl Key
Whether the CTRL key was pressed during an event.
f romEl ement
The object the mouse is moving from.
keyCode
The Unicode encoding of the key typed.
offsetX
The X-coordinate of the event, relative to the container.
offsetY
The Y-coordinate of the event, relative to the container.
reason
Data transfer status.
returnVal ue
Specify a return value for the event handler.
screenX
The screen X-coordinate of the event. JavaScript 1.2.
screenY
The screen Y-coordinate of the event. JavaScript 1.2.
shiftKey
Whether the SHIFT key was pressed during an event.
srcEl ement
The object on which the event occurred.
srcFi 1 ter
The filter that changed.
toEl ement
The object to which the mouse is moving.
type
The type of the event. JavaScript 1.2.
x
The X-coordinate of the event within a positioned ele-
ment. JavaScript 1.2.
y
The Y-coordinate of the event within a positioned ele-
ment. JavaScript 1.2.
Availability
Inherits From
Input, HTMLElement
Synopsis
form, name
form, el ements[ /]
Properties
Methods
FileUpload inherits methods from Input and HTMLElement.
Event Handlers
FileUpload inherits event handlers from Input and HTMLEle-
ment and defines or overrides the following:
onchange
The handler invoked when input value changes.
Availability
Inherits From
HTMLElement
Synopsis
document. form_name
document. forn\s[form_number]
Form
Properties
acti on
The URL for form submission. JavaScript 1.0; read-only in
Internet Explorer 3-
el ements[]
The input elements of the form.
el ements. ength 1
encodi ng
The encoding of form data. JavaScript 1.0; read-only in
Internet Explorer 3-
1 ength
The number of elements in a form.
method
The submission method for the form. JavaScript 1.0; read-
only in Internet Explorer 3.
name
The name of a form.
target
The window for form results. JavaScript 1.0; read-only in
Internet Explorer 3-
Methods
Form inherits methods from HTMLElement and also defines
the following:
reset( )
submi t(
Submit a form.
Function
Event Handlers
Form inherits event handlers from HTMLElement and also
defines the following:
onreset
The handler invoked when a form is reset. JavaScript 1.1.
onsubmi
Invoked when a form is submitted.
Availability
Synopsis
window, f rames[/
window, frames.length
f rames[ 7]
frames .ength
1
Availability
Synopsis
body
}
II Function invocation
functionnamei argument _va ue_l ist) 1
Constructor
Properties
arguments!!]
Arguments passed to a function. JavaScript 1.0; ECMA-
262; deprecated in favor of the Arguments object.
arity
The number of declared arguments. Navigator 4, with
LANGUAGE="JavaScriptl.2".
cal 1 er
The function that called this one.
1 ength
The number of declared arguments. JavaScript 1.1;
ECMA-262.
prototype
The prototype for a class of objects. JavaScript 1.1.
Methods
apply( thisobj args) ,
toString( )
Availability
Inherits From
Input, HTMLElement
History
Synopsis
form, name
form, el ements[7
Properties
val ue
Arbitrary data submitted with a form.
Availability
Synopsis
window, history
frame, hi story
hi story
Properties
current
The URL of the currently displayed document. Navigator
4; requires Uni versal BrowserRead.
length
The number of elements in the history array. Navigator 2,
Internet Explorer 4.
next
The URL of the next document in the history array. Navi-
gator 4; requires Uni versal BrowserRead.
previous
The URL of the previous document in the history array.
HTMLElement
I Methods
backO
Return to the previous URL. JavaScript 1.0.
forward( )
toString( )
Availability
all[]
All elements contained within an element.
chi dren[]
The direct children of an element.
cl assName
The value of the CLASS attribute.
document
The Document object that contains an element.
id
The value of the I D attribute.
innerHTML
The HTML text contained within the element.
innerText
The text within the element.
1 ang
The value of the LANG attribute.
offsetTop
The Y-coordinate of the element.
offsetWidth
The width of the element.
outerHTML
The HTML of an element.
outerText
The text of an element.
parentEl ement
The container of an element.
sourcelndex
The index of the element in Document . al 1 [].
style
The inline CSS style of the element.
tagName
The tag type of an element.
title
Tool tip for an element.
Navigator 4 Methods
handl eEvent(ei/e/7t)
Pass an event to an appropriate handler.
contains( target)
Whether one element is contained in another.
getAttributeCftame)
Get an attribute value.
insertAdjacentHTML(w/7ere, text)
Insert HTML text before or after an element.
insertAdjacentText(iv/?ere, text)
Insert plain text before or after an element.
removeAttribute(/7<3tf?e)
Delete an attribute.
setAttribute(/7d/ne, value)
Set the value of an attribute.
Event Handlers
oncl ick
The handler invoked when the user clicks on an element.
JavaScript 1.2; HTML 4.0.
ondbl cl ick
The handler invoked when the user double-clicks on an
element. JavaScript 1.2; HTML 4.0.
onhel p
The handler invoked when the user presses Fl. Internet
Explorer 4.
onkeydown
The handler invoked when the user presses a key. Java-
Script 1.2; HTML 4.0.
onkeypress
The handler invoked when the user presses a key. Java-
Script 1.2; HTML 4.0.
onkeyup
The handler invoked when the user releases a key. Java-
Script 1.2; HTML 4.0.
onmousedown
The handler invoked when the user presses a mouse but-
ton. JavaScript 1.2; HTML 4.0.
Image
onmousemove
The handler invoked when mouse moves within an ele-
ment. JavaScript 1.2; HTML 4.0.
onmouseout
The handler invoked when mouse moves out of an ele-
ment. JavaScript 1.2; HTML 4.0.
onmouseover
The handler invoked when mouse moves over an ele-
ment. JavaScript 1.2; HTML 4.0.
onmouseup
The handler invoked when the user releases a mouse but-
ton. JavaScript 1.2; HTML 4.0.
Availability
Inherits From
HTMLElement
Synopsis
document. images[ /]
document, images.length
document, image-name
Constructor
Properties
border
The border width of an image.
compl ete
Whether an image load is complete.
height
The height of an image.
hspace
The horizontal padding for an image.
1 owsrc
An alternate image for low-resolution displays.
name
The name of an image.
src
The URL of the embedded image.
vspace
The vertical padding for an image.
width
The width of an image.
Event Handlers
Image inherits event handlers from HTMLElement and also
defines the following:
onabort
The handler invoked when user aborts image loading.
onerror
The handler invoked when an error occurs during image
loading.
onl oad
Handler invoked when an image finishes loading.
Availability
Inherits From
HTMLElement
Synopsis
form, el ements[ i ]
form. name
Properties
checked
Whether a Checkbox or Radio element is checked.
defaul tChecked
A Checkbox or Radio element's default status.
defaul tVal ue
The default text displayed in an element.
form
The Form containing the element.
name
The name of a form element.
type
The type of a form element. JavaScript 1.1.
val ue
The value displayed or submitted by a form element. Nav-
igator 2; buggy in Internet Explorer 3-
Methods
Input inherits methods from HTMLElement and defines or
overrides the following:
blurO
Remove keyboard focus from a form element.
clickO
Simulate a mouseclick on a form element.
JavaArray
focus( )
sel ect(
Select the text in a form element.
Event Handlers
Input inherits event handlers from HTMLElement and defines
or overrides the following:
onbl ur
The handler invoked when a form element loses focus.
onchange
The handler invoked when a form element's value
changes.
oncl ick
The handler invoked when a form element is clicked.
JavaScript1.0; enhanced in JavaScript 1.1.
onfocus
The handler invoked when a form element gains focus.
Availability
Client-side Navigator 3
Synopsis
Properties
1 ength
The number of elements in a Java array.
Availability
Client-side Navigator 3
Synopsis
Properties
Availability
Client-side Navigator 3
Synopsis
Properties
JavaPackage
JavaScript representation of a Java package
Availability
Client-side Navigator 3
Synopsis
Properties
Availability
Synopsis
Layer
Methods
cal {methodName, args[J)
Invoke a method of a JavaScript object.
eval (s)
Evaluate a string of JavaScript code.
getMember(/7<3/77e)
Read a property of a JavaScript object.
getWindow(app7et)
Return initial JSObject for browser window.
removeMember(/73/77e)
Delete a property of a JavaScript object.
setMember(/-73/77e, value)
Set a property of a JavaScript object.
toString( )
Availability
Client-side Navigator 4
Synopsis
document. ayers[
1 /]
Constructor
Properties
above
The layer above this one.
background
The background image of a layer.
below
The layer below this one.
bgCol or
The background color of a layer.
cl ip. bottom
The bottom of the layer's clipping region.
clip.height
The height of the layer's clipping region.
cl ip.l eft
The left edge of the layer's clipping region.
cl ip. right
The right edge of the layer's clipping region.
cl ip.top
The top of the layer's clipping region.
cl ip. width
The width of the layer's clipping region.
document
The Document object of a layer.
hidden
Whether a layer is hidden. Navigator 4; deprecated; use
Layer . vi sibi 1 i ty instead.
layers[]
The layers contained within a layer. Navigator 4; depre-
cated; use Layer .document . 1 ayers instead.
left
The X-coordinate of a layer.
name
The name of a layer. Client-side Navigator 4.
pageX
The X-coordinate of a layer, relative to the page.
pageY
The Y-coordinate of a layer, relative to the page.
parentLayer
The parent of the layer.
si bl ingAbove
The sibling layer above this one.
sibl ingBel ow
The sibling layer below this one.
src
The source URL of a layer's content.
top
The Y-coordinate of a layer.
vi si bi 1 i ty
Whether a layer is visible.
window
The window that contains a layer.
x
The X-coordinate of a layer.
y
The Y-coordinate of a layer.
zlndex
Stacking order of a layer.
Methods
captureEvents(efe/7tmas/c)
Specify event types to be captured.
handl eEvent(e^e/?t )
load(src, width)
Change layer contents and width.
moveBy(c/x, dy)
Move a layer to a relative position.
moveTo(x, y)
Move a layer.
moveToAbsol ute(x, y)
Move a layer to page coordinates.
offset(c/x, dy)
Move a layer to a relative position. Deprecated; use
Layer moveBy(
. ) instead.
rel easeEvents(eve/7t/77as/c)
Stop capturing events.
resizeBy(div, dh)
Resize a layer by a relative amount.
resizeJoiwidth, height)
Resize a layer.
routeEvent(ei/e/7t)
Pass a captured event to the next handler.
Availability
Inherits From
HTMLElement
Synopsis
document. inks[]1
document. links.length
Properties
hash
The anchor specification of a link.
host
The hostname and port portions of a link.
hostname
The hostname portion of a link.
href
The complete URL of a link.
pathname
The path portion of a link.
port
The port portion of a link.
protocol
The protocol portion of a link.
search
The query portion of a link.
target
The target window of a hypertext link.
text
The text of a link. Navigator 4.
x
The X-coordinate of a link. Navigator 4.
y
The Y-coordinate of a link. Navigator 4.
Methods
Link inherits the methods of HTMLElement.
Event Handlers
Link inherits the event handlers of HTMLElement and defines
special behavior for the following three:
oncl ick
The handler invoked when a link is clicked. JavaScript 1.0;
enhanced in JavaScript 1.1.
onmouseout
The handler invoked when the mouse leaves a link. Java-
Script 1.1.
onmouseover
The handler invoked when the mouse goes over a link.
Availability
Synopsis
1ocation
window. ocation
1
Properties
hash
The anchor specification of the current URL.
host
The hostname and port portions of the current URL.
hostname
The hostname portion of the current URL.
href
The complete currently displayed URL.
pathname
The path portion of the current URL.
protocol
The protocol portion of the current URL.
search
The query portion of the current URL.
Methods
rel oad( force)
Reload the current document. JavaScript 1.1.
repl dceiurl )
Math
a placeholder for mathematical functions and constants
Availability
Synopsis
Math. constant
Math. function^ )
Constants
Math.E
The mathematical constant e.
Math.LNIO
The mathematical constant loge 10.
Math.LN2
The mathematical constant log^.
Math.LOGlOE
The mathematical constant log 10 e.
Math.L0G2E
The mathematical constant log2 e.
Math.SQRTl_2
The mathematical constant \/Jl .
Math.SQRT2
The mathematical constant Jl .
Static Functions
Math .abs(x)
Compute an absolute value.
Math.acos(x)
Compute an arc cosine.
Math.atan(x)
Compute an arc tangent.
Math.atan2(x, y)
Compute the angle from the X-axis to a point.
Math.cos(x)
Compute a cosine.
Math .exp(x)
Compute e x .
Math.fl oor(x)
Round a number down.
Math.log(x)
Compute a natural logarithm.
Math .max(a, b)
Return the larger of two values.
Math.minCa, b)
Return the smaller of two values.
MimeType
Math.pow(x, y)
Compute xv.
Math. random(
Return a pseudo-random number. JavaScript 1.1;
ECMA-262.
Math round(x)
Round to the nearest integer.
Math.sin(x)
Compute a sine.
Math sqrt(x)
.
Math.tan(x)
Compute a tangent.
Availability
Client-side Navigator 3
Synopsis
Properties
description
A description of a MIME type.
suffixes
Common file suffixes for a MIME type.
type
The name of a MIME type.
Availability
Synopsis
navigator
Properties
navigator.pl atform
The operating system the browser is running under.
JavaScript 1.2.
navigator.pl ugins[]
An array of installed plugins. JavaScript 1.1; always empty
in Internet Explorer 4.
Number
Functions
navigator. Java Enabled
Test whether Java is available. JavaScript 1.1.
navigator.pl ugins.refreshO
Make newly installed plugins available. Navigator 3.
navigator. savePreferencesO
Save the user's preferences. Navigator 4; requires
Uni versal Pref erencesWri te privilege.
deprecated.
Availability
Synopsis
Number .constant
Constructor
Constants
Number. MAX_VALUE
The maximum numeric value.
Number. MIN_VALUE
The minimum numeric value.
Object
Number. NaN
The special not-a-number value.
Methods
toStri ng(rac/7'x)
Convert a number to a string.
Object
a superclass that contains features of all JavaScript objects
Availability
Constructor
new Object( )
Properties
constructor
An object's constructor function. JavaScript 1.1;
ECMA-262.
Methods
assign( va lue)
Overload the assignment operator. Navigator 3;
eval (code)
Evaluate JavaScript code in a string. Navigator 3;
Option
toString( )
unwatch(prop/7a/77e)
Remove a watchpoint. Navigator 4.
val ueOf(typehint)
The primitive value of the specified object. JavaScript 1.1;
ECMA-262.
watchipropname, hand! er)
Set a watchpoint. Navigator 4.
Availability
Inherits From
HTMLElement
Synopsis
Properties
index
The position of the option.
selected
Whether the option is selected.
text
The label for an option. JavaScript 1.0; read/write in
JavaScript 1.1.
Plugin
val ue
The value returned when the form is submitted.
Availability
Inherits From
Input, HTMLElement
Synopsis
form, name
form, el ements[ /
Properties
Methods
Password inherits methods from Input and HTMLElement.
Event Handlers
Password inherits methods from Input and HTMLElement.
Availability
Client-side Navigator 3
Synopsis
navigator.pl ugins[/]
navigator.pl ugins[ 'name 1
Properties
description
English description of a plugin.
f i 1 ename
The filename of the plugin program.
1 ength
The number of MIME types supported.
name
The name of a plugin.
Availability
Client-side Navigator 4
Synopsis
Methods
di sabl ePri vi 1 eg e(pr f i/7 lege)
Disable a privilege.
Availability
RegExp
I Inherits From
Input, HTMLElement
Synopsis
Properties
checked
Whether a Radio button is selected.
defaul tChecked
Initial state of a Radio button.
val ue
Value returned when form is submitted.
Methods
Radio inherits methods from Input and HTMLElement.
Event Handlers
Radio inherits event handlers from Input and HTMLElement
and defines or overrides the following:
oncl ick
The handler invoked when a Radio button is selected.
Availability
Constructor
RegExp
Instance Properties
gl obal
Whether a regular expression matches globally. Not
implemented in IE 4.
ignoreCase
Whether a regular expression is case-insensitive. Not
implemented in IE 4.
1 astlndex
The character position after the last match. Not imple-
mented in IE 4.
source
The text of the regular expression.
Static Properties
RegExp. %n
The text that matched the nth subexpression.
RegExp. input or RegExp. $_
The input buffer for pattern matching. Non-functional in
IE 4.
Reset
Methods
compi einewpattern attributes)
,
test(string)
Test whether a string contains a match.
Availability
Inherits From
Input, HTMLElement
Synopsis
form, name
form, el ements[ /]
Properties
val ue
The label of a Reset button.
Methods
Reset inherits the methods of Input and HTMLElement.
Event Handlers
Reset inherits the event handlers of Input and HTMLElement
and defines or overrides the following:
Screen
oncl ick
The handler invoked when a Reset button is clicked.
JavaScript 1.0; enhanced in JavaScript 1.1.
Availability
Synopsis
screen
Properties
screen height
The height of the screen.
screen .width
The width of the screen.
Availability
Inherits From
Input, HTMLElement
Synopsis
form. element_name
form, el ementsE/ ]
Properties
1 ength
The number of options in a Select object.
optionsE]
The choices in a Select object. JavaScript 1.0; enhanced in
JavaScript 1.1.
1
se ectedlndex
The selected option. JavaScript 1.0; writeable in JavaScript
1.1.
type
Type of form element. JavaScript 1.1.
Methods
Select inherits the methods of Input and HTMLElement.
Event Handlers
Select inherits event handlersfrom Input and HTMLElement
and defines or overrides the following:
onchange
The handler invoked when the selection changes.
Availability
Constructor
Properties
length
The length of a string. JavaScript 1.0; ECMA-262.
Methods
anchoriname)
Add an HTML anchor to a string.
big()
Make a string <BIG>.
blinkO
Make a string <BLINK>.
boldO
Make a string bold with <B>.
charAt(A?)
Get the /7th character from a string. JavaScript 1.0; ECMA-
262.
charCodeAt(/7)
Get the nth character code from a string. JavaScript 1.2;
ECMA-262.
concat( va lue, . . . )
fixedO
Make a string fixed- width with <TT>.
fontcol or(color)
Set a string's color with <F0NT>.
String
fontsize(sfze)
Set a string's font size with <F0NT>.
match(regexp)
Find one or more regular expression matches. JavaScript
1.2.
search(regexp)
Search for a regular expression. JavaScript 1.2.
sMceistart, end)
Extract a substring. JavaScript 1.2.
smal 1 (
ECMA-262.
stri ke(
Strike out a string with <STRIKE>.
sub()
Make a string a subscript with <SUB>.
substristart, length)
Extract a substring. JavaScript 1.2.
Style
sup( )
tol_owerCase( )
Static Methods
String. f romCharCode(ci , c2, . . . )
ECMA-262.
Availability
Synopsis
// Navigator
document, cl asses .cl assName. tagName
document, ids .elementName
document. tags tagName
document, contextual (...)
// Internet Explorer
html Element styl .
Properties
Methods
borderWidths( top, right, bottom, left)
Set all border width properties. Navigator 4.
Availability
Inherits From
Input, HTMLElement
Synopsis
form. name
form, el ements[/ ]
Properties
val ue
The label of a Submit button.
Methods
Submit inherits the methods from Input and HTMLElement.
Event Handlers
Submit inherits event handlers from Input and HTMLElement
and defines or overrides the following:
oncl ick
Invoked when a Submit button is clicked. JavaScript 1.0;
enhanced in JavaScript 1.1.
Availability
Inherits From
Input, HTMLElement
Synopsis
form, name
form, el ements[/]
Properties
val tie
Methods
Text inherits the methods of Input and HTMLElement.
Event Handlers
Text inherits the event handlers of Input and HTMLElement
and defines or overrides the following:
onchange
The handler invoked when input value changes.
Availability
Inherits From
Input, HTMLElement
URL
Synopsis
form, name
form, el ements[ /
Properties
Methods
Textarea inherits the methods of Input and HTMLElement.
Event Handlers
Textarea inherits the event handlers of Input and HTMLEle-
ment and defines or overrides the following:
onchange
The handler invoked when input value changes.
Availability
Synopsis
self
window
window, f rames[/
Properties
defaul tStatus
The default status line text.
document
The Document of the window.
f rames[]
List of frames within a window.
hi story
The History of the window.
1 ength
The number of frames in the window.
1 ocation
The URL of the window.
name
The name of a window. JavaScript 1.0; read/write in
JavaScript 1.1.
navigator
A reference to the Navigator object.
off screenBufferi ng
Whether window updates are buffered. JavaScript 1.2.
opener
The window that opened this one. JavaScript 1.1.
parent
The parent of a frame.
screen
Information about the screen. JavaScript 1.2.
self
The window itself.
status
Specify a transient status-line message.
top
The window of a frame.
Navigator Properties
crypto
Reference to the Crypto object. Navigator 4.04 and later.
innerHeight
The height of the document display area. Navigator 4;
Universal BrowserWri te privilege required to set to less
than 100 pixels.
innerWidth
The width of the document display area. Navigator 4;
Uni versal BrowserWri te privilege required to set to less
than 100 pixels.
Java
The Java.* LiveConnect package. Navigator 3.
1 ocationbar
The visibility of the browser's location bar. Navigator 4;
Universal BrowserWri te privilege required to change
visibility.
menubar
The visibility of the browser's menubar. Navigator 4;
Universal BrowserWri te privilege required to change
visibility.
netscape
The netscape.* LiveConnect Java package. Navigator 3.
outerHeight
The height of the window area. Navigator 4;
Uni versal BrowserWri te privilege required to set to less
outerWidth
The width of the window. Navigator 4;
Universal BrowserWri te privilege required to set
to less than 100 pixels.
pageXOffset
The current horizontal scroll position. Navigator 4.
pageYOffset
The current vertical scroll position. Navigator 4.
personal bar
The visibility of the browser's personal bar. Navigator 4;
Uni versal BrowserWri te privilege required to change
visibility.
screenX
The X-coordinate of a window on the screen. Navigator 4.
screenY
The Y-coordinate of a window on the screen. Navigator 4.
scrol 1 bars
The visibility of the browser's scroll bars. Navigator 4;
UniversalBrowserWrite privilege required to change
visibility.
statusbar
The visibility of the browser's status line. Navigator 4;
UniversalBrowserWrite privilege required to change
visibility.
sun
The sun.* LiveConnect Java package. Navigator 3-
tool bar
The visibility of the browser's toolbar. Navigator 4;
cl ientlnformation
Synonym for W i ndow . nav i gator . Internet Explorer 4.
event
Describes the most recent event. Internet Explorer 4.
Window
Methods
The Window object has the following portable methods.
Non-portable, browser-specific methods are listed after
this list.
al ert(message)
Display a message in a dialog box.
blurO
Remove keyboard focus from a top-level window.
JavaScript 1.1.
cl earTimeout( timeoutld)
Cancel deferred execution.
cl ose(
Close a browser window.
conf rm(question)
Ask a yes-or-no question.
focus( )
moveBy(c/x, dy)
Move a window to a relative position. JavaScript 1.2;
Navigator 4 requires UniversalBrowserWrite privilege
to move the window off-screen.
moveTo(x, y)
Move a window to an absolute position. JavaScript 1.2;
Window
resizeBy(c/iv, dh)
Resize a window by a relative amount. JavaScript 1.2.
Navigator 4 requires UniversalBrowserWrite privilege
to set either width or height to less than 100 pixels.
re si zeJoiwidth, height)
Resize a window. JavaScript 1.2; Navigator 4 requires
Universal BrowserWri te privilege to set either width or
height to less than 100 pixels.
scrol (x, y)
Scroll a document in a window. JavaScript 1.1; deprecated
in JavaScript 1 .2 in favor of s c r o 1 1 To ( )
scrollTo(x, y)
Scroll the document. JavaScript 1.2.
Navigator 4 Methods
dtob(str64)
Decode base-64 encoded data.
backO
Go back to previous document.
btod(data)
Encode binary data using base-64 ASCII encoding.
captureEventsieventmask)
Specify event types to be captured.
disableExternalCaptureO
Disable cross-server event capturing. Requires
Uni versal BrowserWri te privilege.
Window
enabl e External Capture( )
forward( )
home(
Display the home page.
print( )
routeEvent(e\/e/7t )
setHotkeys(e/7<3t>7ec/)
Allow or disallow keyboard shortcuts. Requires
Uni versal BrowserWri te privilege.
setResizabl e(resizable)
Allow or disallow window resizing. Requires
Universal BrowserWri te privilege.
setZ0ptions(opt7on)
Control window stacking. Requires
Uni versal BrowserWri te privilege.
stop( )
navigate(i/r7 )
ondragdrop
The handler invoked when the user drops items in the
window. Navigator 4.
onerror
The handler invoked when a JavaScript error occurs.
JavaScript 1.1.
onfocus
Invoked when window is given focus. JavaScript 1.1.
onload
The handler invoked when a document finishes loading.
onmove
The handler invoked when a window is moved. Navigator
4; not supported on Navigator 4 Unix platforms.
onresize
The handler invoked when a window is resized.
JavaScript 1.2.
onunl oad
The handler invoked when the browser leaves a page.
Web Programming
from O'Reilly
^
WebMaster in a Nutshell, CGI Programming on the
Deluxe Edition World Wide Web
By O'Reilly & Associates, Inc. By Shishir Gundavaram
1st Edition September 1997 1st Edition March 1996
374 pages, includes CD-ROM & book 450 pages, ISBN 1-56592-168-2
ISBN 1-56592-305-7
Learning VBScript
Dynamic HTML: The Definitive By Paul Lomax
Reference 1st Edition July 1997
By Danny Goodman 616 pages, includes CD-ROM
1st Edition July 1998 ISBN 1-56592-247-6
1088 pages, ISBN 1-56592-494-0
OREILLY*
to order: 800-998-9938 • [email protected] • http://www.oreilly.com/
O'REILLY*
J7^> Printed on
US $7.95
ISBN 1-56592-521-1 CAN $11.95 {£3$ Recycled Paper
90000
mi 36920 92521"
9 ,
781565"925212 6 7