| home / programming / prof_java / 1 | [previous] [next] |
|
|
SVG adopted a similar version of the <script/> tag for including JavaScript in its pages. This <script/> tag, however, is different from its HTML sibling::
|
For example:

In this code, the two <script/> tags are correct for SVG.
The first, containing inline code, is surrounded by a CDATA section so no problems
arise if you use special characters; the second uses the xlink:href attribute
to reference an external file.
Because no <head/> area exists in SVG, <script/> tags can be placed nearly anywhere. Typically, however, they are placed:
|
The <script/> tag cannot be placed inside of shapes, such
as <rect/> or <circle/>, nor can they
be placed inside of filters, gradients, or other appearance-defining tags.
You can’t really talk about JavaScript in the browser without talking about the Browser Object Model (BOM), which provides objects that interact with the browser window independent of the content.
The BOM is made up of a series of objects that are related to one another. Figure 5-3 shows the basic BOM hierarchy.

As you can see, the window object is the center of the BOM universe, with all objects and collections somehow connecting back to it. I begin the discussion of the BOM with this object.
The window object represents an entire browser window, but not
necessarily the content that the window
contains. Rather, window can be used to move, resize, and otherwise
affect the browser that it
represents.
If a page uses framesets, each frame is represented by its own window
object and stored in the frames collection. Within the frames
collection, the window objects are indexed both by number (starting at 0, going
first left-to-right, then row-by-row) and by the name of the frame. Consider
the following example:

This code creates a frameset with one frame across the top and two frames underneath.
Here, the top
frame can be referenced by window.frames[0] or window.frames[“topFrame”],
however, you would
probably use the top object instead of window to refer
to these frames (making it top.frames[0], for
instance).
The top object always points to the very top (outermost) frame,
which is the browser window itself. This
assures that you are pointing to the correct frame. If you then write code within
a frame, the window
object referenced in it is a pointer to just that frame.
Because the window object is the center of the BOM universe, it enjoys a special
privilege: You don’t need to explicitly reference it. Whenever a function,
object, or collection is referenced, the interpreter always looks to the window
object, so window.frames[0] can be rewritten as just frames[0].
To understand the various ways to reference the frames in the previous example,
refer to Figure 5-4.

It is also possible to access a frame directly using its name, such as
window.leftFrame. However, using theframescollection is generally more acceptable because it more accurately represents the code’s intent.
| home / programming / prof_java / 1 | [previous] [next] |
Created: March 27, 2003
Revised: June 20, 2005
URL: http://webreference.com/programming/prof_java/1