[Next] [TOC]
Introduction
This document describes the changes and new features for JavaScript
in Navigator 4.0. These features will be included in the new JavaScript
Guide at a later date. For additional information about JavaScript, see
the "JavaScript
Guide."
Feature Summary
Event Model
The event model has changed to include a
new event object, new events, and event capturing.
- event object -- contains properties
that describe a JavaScript event, such as the event type and the cursor
location at the time of the event. The object is passed as an argument
to an event handler when an event occurs.
- event capturing -- enables
a window, frame, or document to capture an event before the target object
(link, button, etc.) gets the event. JavaScript implements event capturing
with the following new methods:
- captureEvents -- sets the window
or document to capture the specified events.
- disableExternalCapture
-- disables external event capturing set by the enableExternalCapture
method.
- enableExternalCapture
-- allows a window with frames to capture events in pages loaded from different
locations (servers).
- releaseEvents -- sets the window
or document to release the specified events.
- routeEvent -- routes the event
from its capturer through its normal event hierarchy.
- handleEvent -- fires the event
handler for the specified event.
- Events have been added or revised.
- Click* -- occurs when a user clicks
a link or form element.
- DblClick -- occurs when a user double-clicks
over a link or form element.
- DragDrop -- occurs when a user
drops an object onto a Navigator window.
- KeyDown -- occurs when a user depresses
a key.
- KeyPress -- occurs when a user
presses or holds down a key.
- KeyUp -- occurs when a user releases
a key.
- MouseDown -- occurs when a user
depresses a mouse button.
- MouseMove -- occurs when a user
moves the cursor.
- MouseOut* -- occurs when a user
moves the cursor out of an object.
- MouseOver* -- occurs when a user
moves the cursor over an object.
- MouseUp -- occurs when a user releases
a mouse button.
- Move -- occurs when a user or script
moves a window or frame.
- Resize -- occurs when a user or script
resizes a window or frame.
Functions
Layers
Layers, new in Navigator 4.0, let you define overlapping layers of transparent
or solid content in a web page. Each layer in HTML has a corresponding
layer object that allows you to use JavaScript to manipulate the layer.
For information on using layers, see "Dynamic
HTML in Netscape Communicator." Note that this link takes you
to a different set of documents.
Methods
Array Methods
- concat -- joins two arrays and returns
a new array.
- slice -- extracts a section from an
array and returns a new array
- sort* -- now works on all platforms.
It no longer converts undefined elements to null and sorts them to the
high end of the array.
Document Method
- getSelection -- returns a string
containing the text of the current selection.
Navigator Method
- preference -- allows a script
to get and set certain Navigator preferences, such
as enabling or disabling Java.
String Methods
- charCodeAt -- returns a number
specifying the ISO-Latin-1 codeset value of the character at the specified
index in a string object.
- concat -- combines the text of two
strings and returns a new string.
- fromCharCode -- constructs
a string from a specified sequence of numbers that are ISO-Latin-1 codeset
values.
- match -- executes a search for a match
between a string and a regular expression.
- replace -- executes a search for
a match between a string and a regular expression, and replaces the matched
substring with a new substring.
- search -- tests for a match between
a string and a regular expression
- slice -- extracts a section of an
string and returns a new string.
- split* -- includes the following new
features and changes:
- It can take a regular expression argument, as well as a fixed string,
by which to split the object string.
- It can take a limit count so that it won't include trailing empty elements
in the resulting array.
- If you specify LANGUAGE="JavaScript1.2" in the <SCRIPT>
tag, string.split(" ") splits on any run of one
or more white space characters including spaces, tabs, line feeds, and
carriage returns.
- substr -- returns the characters
in a string collecting the specified number of characters beginning with
a specified location in the string.
- substring* -- no longer swaps
index numbers when the first index is greater than the second. For this
behavior, LANGUAGE="JavaScript1.2" must be specified in the <SCRIPT>
tag.
Window Methods
- back -- points the Navigator window
to the previous URL in the current history list.
- disableExternalCapture
-- disables external capturing of events.
- enableExternalCapture
-- allows a window with frames to capture events in pages loaded from different
locations.
- find -- finds the specified text string
in the contents of the window.
- forward -- points the Navigator window
to the next URL in the current history list.
- home -- points the Navigator window
to the URL specified in the preferences as the user's home page.
- moveBy -- moves the window by the
specified amount
- moveTo -- moves the window to the
specified coordinates
- open -- includes the following new window
features:
- alwaysLowered -- forms a new window
which floats below the other screen windows, whether it is currently active
or not.
- alwaysRaised -- forms a new window
which floats on top of the other screen windows, whether it is currently
active or not.
- dependent -- creates a new window as a child of an existing
window.
- hotkeys -- disables most hotkeys in a new window.
- innerHeight and innerWidth -- reflect
the size of the Navigator window's content area.
- replace height and width. Both
are kept for backwards compatibility.
- outerHeight and outerWidth -- reflect
the size of the Navigator window's outside boundary.
- screenX -- the distance the new
window is placed from the left side of the screen
- screenY -- the distance the new
window is placed from the top of the screen
- titlebar -- creates a window with a titlebar.
- z-lock -- forms a new window which
does not rise above other windows when given focus.
- resizeBy -- resizes the window by
the specified amount
- resizeTo -- resizes the window to
the specified size
- scrollBy -- scrolls the window by
the specified amount
- scrollTo -- scrolls the window to
the specified coordinates
- scrollTo extends the capabilities of scroll. scroll remains for backward
compatibility
- stop -- stops the current download.
Shared Methods
- captureEvents -- window and
document method. Sets the window or document to capture the specified events.
- clearInterval -- window and
frame method. Cancels setInterval.
- handleEvent -- method of all
objects with event handlers. Invokes the handler for the specified event.
- print -- window and frame method. Prints
the contents of the window or frame.
- releaseEvents -- window and
document. Sets the window or document to release the specified events.
- routeEvent -- window and document
method. Passes a captured event along the normal event hierarchy.
- setInterval -- window and frame
method. Repeatedly calls a function or evaluates an expression after a
specified number of milliseconds has elapsed.
- setTimeout* -- can now be used
to either evaluate an expression or call a function.
- toString* -- converts the object
or array to a literal. For this behavior, LANGUAGE="JavaScript1.2"
must be specified in the <SCRIPT> tag.
Objects
- You can create objects using literal
notation.
- arguments -- includes new properties
that provide information about the invoked function.
- Array* -- includes the following new
features and changes:
- Literal notation -- arrays
can now be created using literal notation
- Under JavaScript 1.2 -- when the <SCRIPT>
tag includes LANGUAGE="JavaScript1.2," array(1) creates a new
array with a[0]=1
- With regular expressions -- When created
as the result of a match between a regular expression and a string, arrays
have new properties that provide information about the match
- Number* -- now produces NaN
rather than an error if x is a string that does not contain a
well-formed numeric literal.
- screen -- contains information about
the display screen resolution and colors.
- String* -- has new methods as described
in String Methods.
Operators
- Equality operators* (= = and !=)
If the <SCRIPT> tag uses LANGUAGE=JavaScript1.2, the equality
operators = = and != don't try to convert operands from
one type to another, and always compare identity of like-typed operands.
- delete -- deletes an object, an object's
property, or an element at a specified index in an
array.
Properties
Function Property
- arity -- indicates
the number of arguments expected by a function.
Navigator Properties
- language -- indicates what translation
of the Navigator is being used. This property is particularly useful for
JAR management.
- platform -- indicates the machine
type for which the Navigator was compiled. This property is particularly
useful for JAR management.
Window Properties
- innerHeight -- specifies the vertical
dimension, in pixels, of the window's content area.
- innerWidth -- specifies the horizontal
dimension, in pixels, of the window's content area.
- locationbar -- object that allows
you to show or hide the location bar of the targeted window.
- menubar -- object that allows you to
show or hide the menu bar of the targeted window.
- outerHeight -- specifies the vertical
dimension, in pixels, of the window's outside boundary.
- outerWidth -- specifies the horizontal
dimension, in pixels, of the window's outside boundary.
- pageXOffset -- specifies the x-position,
in pixels, of the window's viewed page.
- pageYOffset -- specifies the y-position,
in pixels, of the window's viewed page.
- personalbar -- object that allows
you to show or hide the personal bar (also known as the directories bar)
of the targeted window.
- scrollbars -- object that allows
you to show or hide the scroll bar of the targeted window.
- statusbar -- object that allows you
to show or hide the status bar of the targeted window.
- toolbar -- object that allows you to
show or hide the tool bar of the targeted window.
Regular Expressions
Regular expressions are patterns used to match
character combinations in strings. In JavaScript, you create a regular
expression as an object which has methods used to execute a match against
a string. You can also pass the regular expression as arguments to the
String methods match, replace, search, and split. A global RegExp object
has properties most of which are set when a match is successful, such as
lastMatch which specifies the last successful match. Finally, the array
object has new properties that provide information about a successful match
such as the input which specifies the original input string against which
the match was executed.
This section includes:
Signed Scripts
For additional power and functionality, scripts can now gain access
to normally restricted information. This is achieved through signed
scripts that request expanded privileges. This new functionality provides
greater security than tainting.
Statements
- The break* and continue*
statements can now be used with the new labeled statement.
- do while statement -- repeats a loop
until the test condition evaluates to false.
- export -- allows
a signed script to provide properties, functions, and objects to other
signed or unsigned scripts.
- import -- allows
a script to import properties, functions, and objects from a signed script
which has exported the information.
- labeled statement -- allows the program
to break outside nested loops or to continue a loop outside the current
loop.
- switch statement -- allows the program
to test several conditions easily.
Style Sheets
Using style sheets, you gain finer control over the presentation of
your web pages. Navigator 4.0 supports two syntaxes for designing style
sheets: Cascading Style Sheets (CSS) and JavaScript style sheets. CSS is
the static approach to specifying style and JavaScript is the programmatic
approach.
For information on using style sheets, see "Dynamic
HTML in Netscape Communicator." Note that this link takes you
to a different set of documents.
Miscellaneous
Compatibility With Earlier Versions of Navigator
As JavaScript evolves along with Navigator, its capabilities expand
greatly. This means that JavaScript written for Navigator 4.0 may work
in Navigator 4.0 only. To ensure that users of earlier versions of Navigator
avoid problems when viewing pages that use JavaScript 1.2, use the LANGUAGE
attribute in the <SCRIPT> tag to indicate which version of Javascript
you're using. If you use LANGUAGE="JavaScript1.2", you need to
be aware of the equality rules described
below.
Statements within a <SCRIPT> tag are ignored if the browser does
not have the level of JavaScript support specified in the LANGUAGE attribute;
for example:
- Navigator 2.0 executes code within the <SCRIPT LANGUAGE="JavaScript">
tag; it ignores code within the <SCRIPT LANGUAGE="JavaScript1.1">
and <SCRIPT LANGUAGE="JavaScript1.2"> tags.
- Navigator 3.0 executes code within the <SCRIPT LANGUAGE="JavaScript">
and <SCRIPT LANGUAGE="JavaScript1.1"> tags; it ignores
code within the <SCRIPT LANGUAGE="JavaScript1.2"> tag.
- Navigator 4.0 executes code within the <SCRIPT LANGUAGE="JavaScript">,
<SCRIPT LANGUAGE="JavaScript1.1">, and <SCRIPT LANGUAGE="JavaScript1.2">
tags.
By using the LANGUAGE attribute, you can write general JavaScript that
Navigator version 2.0 and higher recognize, and include additional or refined
behavior for newer versions of Navigator.
[Next] [TOC]
Copyright © 1997 Netscape Communications Corporation