[Contents]
[Previous] [Next] [Last]This document describes the changes and new features for JavaScript in Navigator 4.0. For additional information about JavaScript, see the JavaScript section of the
DevEdge library.In addition to the information in this document,
DevEdge contains other articles and tutorials explaining the use of some of the new features of JavaScript 1.2. For example, visit View Source, Netscape's online technical magazine for developers, or JavaScript Developer Central, a centralized location for much information about JavaScript, including sample code, tech notes, and other articles.The event model, as described in
Chapter 1, "Event Model," has changed to include a newevent
object, new
events, and event capturing.
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.
Objects that receive events have these new methods for event capturing:
routeEvent
--routes
the event from its capturer through its normal event hierarchy.
handleEvent
--fires
the event handler for the specified event.
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.
Resize
--occurs
when a user or script resizes a window.
Number
--converts
a specified object to a number.
String
--converts
a specified object to a string.
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.concat
--joins
two arrays and returns a new array.
pop
removes the last element from an array and returns that element.
push
adds one or more elements to the end of an array and returns that last element added.
shift
removes the first element from an array and returns that element
unshift
adds one or more elements to the front of an array and returns the new length of the
array.
slice
--extracts
a section from an array and returns a new array
splice
--adds
and/or removes elements from an array and returns the removed elements.
sort
*--now
works on all platforms. It no longer converts undefined elements to null; instead, it
sorts them to the high end of the array.
getSelection
--returns
a string containing the text of the current selection.
preference
--allows
a script to get and set certain Navigator preferences, such as enabling or disabling Java.
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:
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
*--if
you specify LANGUAGE="JavaScript1.2"
in the <SCRIPT>
tag, this method no longer swaps index numbers when the first index is greater than the
second.
back
--undoes
the last history step in any frame within the top-level window, not just backing up a step
in the frame in which the call to back
occurs.
clearInterval
--cancels
setInterval.
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
--enables or disables most hotkeys in a new window. innerHeight
and innerWidth
--reflect the size of the Navigator
window's content area. These replace height
and width
, which 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. print
--prints
the contents of the window.
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
replaces scroll
. scroll
remains for backward compatibility
setInterval
--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.
stop
--stops
the current download.
eval
--no
longer a method of individual objects; only available as a global function.
watch
--new
method of all objects. Watches for a property to be assigned a value and runs a function
when that occurs.
unwatch
--new
method of all objects. Removes a watchpoint set with the watch
method.
captureEvents
--window
and document
method. Sets the window or document to capture the specified
events.
handleEvent
--method
of all objects with event handlers. Invokes the handler for the specified event.
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.
toString
*--converts
the object or array to a literal. For this behavior, LANGUAGE="JavaScript1.2"
must be specified in the <SCRIPT>
tag.
arguments
--includes
new properties that provide information about the invoked function.
Array
*--includes
the following new features and changes:
<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" on page 12.
==
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 property or an element at a specified index in an array.
<A>
tag.arity
--indicates
the number of arguments expected by a function.
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.
innerHeight
--specifies
the vertical dimension, in pixels, of the window's content area; replaces height
.
innerWidth
--specifies
the horizontal dimension, in pixels, of the window's content area; replaces width
.
height
--replaced by innerHeight
; height
remains
only for backward compatibility. In earlier releases, if you set this property to a number
smaller than 100, JavaScript rounded it up to 100. In 4.0, it does a security check to see
if the script can set the property to a number smaller than 100.width
--replaced by innerWidth
; width
remains only
for backward compatibility. In earlier releases, if you set this property to a number
smaller than 100, JavaScript rounded it up to 100. In 4.0, it does a security check to see
if the script can set the property to a number smaller than 100.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 bars 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
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 theString
methods match
, replace
, search
,
and split
. The RegExp
construction 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 input
which specifies
the original input string against which the match was executed.
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 data tainting. Data tainting has been removed from JavaScript 1.2.
break
*
and continue
*
statements can now be used with the new labeled
statement.
do
while
--repeats a loop until the test condition evaluates to false.
export
--allows
a signed script to provide functions to other signed or unsigned scripts.
import
--allows
a script to import functions from a signed script which has exported the information.
labeled
--allows
the program to break outside nested loops or to continue a loop outside the current loop.
switch
--allows
the program to test several conditions easily.
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.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.
<SCRIPT>
tag are ignored
if the browser does not have the level of JavaScript support specified in the LANGUAGE
attribute; for example:
<SCRIPT
LANGUAGE="JavaScript">
tag; it ignores code within the <SCRIPT
LANGUAGE="JavaScript1.1">
and <SCRIPT
LANGUAGE="JavaScript1.2">
tags. <SCRIPT
LANGUAGE="JavaScript">
and <SCRIPT
LANGUAGE="JavaScript1.1">
tags; it ignores code within the <SCRIPT
LANGUAGE="JavaScript1.2">
tag.<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.
[Contents]
[Previous] [Next] [Last]Last Updated: 10/22/97 11:47:58
Copyright © 1997 Netscape Communications Corporation