By Mark Lavi Technology Evangelist, Netscape Communications
INTRODUCTION
JavaScript 1.2 in Netscape Communicator's Navigator 4.0 component has
greatly advanced the knowledge and control JavaScript has over the user
experience. JavaScript 1.2 can create and dynamically manipulate rich functioned
windows, load HTML 3.2 content into them, and capture many user interface
events. This gives the JavaScript developer an unprecedented opportunity to
control the user experience in the Communicator environment, giving the
developer a robust, light-weight way to create crossware applications.
This TechNote assumes the reader is familiar with the JavaScript
object hierarchy of documents, windows, and frames in Navigator as
well as familiar with signed JavaScript.
The body of this document may be browsed and printed with any browser, but
this TechNote also contains interactive demonstrations of the new
functionality and requires a JavaScript 1.2 capable browser to try them.
OVERVIEW
Netscape has made the new Navigator 4.0 basic user interface and
features, toolbars, and navigation button functions accessible by
JavaScript 1.2. An overview of what's new and modified for window features:
These window properties are expressed in pixel dimensions. These properties
are initially set upon window creation with the open method and can be dynamically
manipulated by the new window methods.
Window properties that begin with "inner"
(innerHeight, innerWidth) represent a pixel dimension of the
referenced window's content area. Window properties that begin with "outer"
(outerHeight, outerWidth) represent a pixel dimension of the
referenced window's outer boundary.The outer boundary includes the scroll
bars, the status bar, the tool bars, and other "chrome" (window border
user interface elements).
The toolbars may now be dynamically displayed (shown or hidden) when controlled by
signed JavaScript. The figure shows Navigator 4.0 Toolbars, they are named (from the top to the
bottom):
menubar: the drop-down menus -- File, Edit, View, Go, Communicator, etc.
toolbar: the navigation buttons -- Back, Forward, Reload, Home, etc.
locationbar: the bookmark and URL areas.
personalbar: the user's personal easy access bookmarks.
scrollbars: vertical and horizontal
document scrollbars.
statusbar: security indicator, Navigator status, etc.
All of the toolbars are objects with one property: visible. Visible is binary, it
may be set to [true or false], or set to [1 or 0], respectively to represent displayed
or hidden toolbar object state. The following example would make the referenced window
"chromeless" (chromeless windows lack toolbars, scrollbars, status areas, etc.
much like a dialog box) by hiding most of the user interface toolbars:
This section includes working interactive examples of JavaScript
1.2 new window methods. The first example is a demonstration of
navigation frameset (nav_frameset.html) which contains two rows of frames,
window methods in the top row navigation frame control the display in the
lower row content frame. The second example shows dynamic
manipulation of a window (dynamic.html).
These examples illustrate how JavaScript 1.2 can reproduce Navigator 4.0's
navigation toolbar button functionality for a window. Please open a new window
by selecting the button before trying any of these navigation examples:
Previously, the JavaScript developer could only set window properties at window
creation, forcing the developer to close an existing window and open a new window
with different window properties. Here are working examples of how JavaScript can
dynamically manipulate a window after it is created.
The parameters used by these methods are either absolute or relative coordinates
in pixel units, given as: (horizontal x-coordinate, vertical y-coordinate).
The origin of the axes is at absolute position (0,0), which is the upper left-hand
corner of the entire display.
The open window method creates a new web browser window. The
syntax remains the same for the open method arguments (URL,
windowname, windowfeatures) and the windowfeatures argument is still a
comma delimited list (i.e.: option=value,option2=value). However,
the windowfeatures argument has been expanded to include new options:
alwaysRaised, alwaysLowered (binary valued, requires signed JavaScript)
When set to true, these methods will create a window that floats above or below
(respectively) all the other windows. Setting to false gives the window
normal behavior, allowing other windows to display over and under it.
z-lock (binary valued, requires signed JavaScript)
When set to true, creates a new window that will not rise above other
existing windows (in contrast to alwaysRaised which will
rise above all existing and future created windows). This feature may deviate
based upon the underlying operating system's window manager, a z-locked window
may be below all other Navigator controlled windows or it may be below all windows.
dependent (binary valued)
When set to true, creates a new child window (a new separate window,
outside of the current window) and makes the current window it's parent.
If the parent window is closed, all the children will close as well.
hotkeys (binary valued)
When set to true, disables most hotkeys with the exception of the security and quit
(i.e.: CONTROL-key and ALT-key combinations) in a new window without a menubar.
innerHeight, innerWidth, outerHeight, outerWidth (pixel values)
These options set the new window properties, they are explained in the
corresponding section of this TechNote (above).
Note: innerHeight and innerWidth options replace the
height and width options,
but they remain for backwards compatibility.
screenX, screenY (pixel values)
The location of the upper left-hand corner of the new window, in relation to
the origin (0,0) of the upper left-hand corner of the user's display.
titlebar (binary valued, requires signed JavaScript)
Creates a window with a displayed or hidden title bar,
when set to true or false, respectively.
Binary values are set to [yes or no] or [1 or 0], respectively. The pixel values
are positive integers falling into the current dimensions of the display screen.
Pixel values with negative values, with dimensions smaller than 100x100, or
with dimensions that exceed the viewable screen (placing a portion or all of the
window off screen) require signed JavaScript. Signed JavaScript is required for
setting any of window features that fall outside of the user's direct control.
RELATED NEW FUNCTIONALITY IN
JAVASCRIPT 1.2
Two new features round out JavaScript's new window capabilities: an
additional document method yields information on user interaction
and a new object which gives you the current display screen properties.
Creating signed JavaScripts is not covered in this TechNote. It requires
processing your JavaScript file(s) with Netscape Object Signing Tools to sign
the files and then sourcing the archive with the new ARCHIVE and ID attributes
of the <SCRIPT> HTML tag. Signed JavaScript has extended capabilities
for cases where user security or user control may be compromised.