11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

One major difference between version 4+ models and the basic model is the addition of the<br />

Event object. This object gives event handlers a snapshot of the context in which the event<br />

occurred. For example, it includes the screen coordinates of the event, the mouse button that<br />

was used (if any), and any modifying keys, such as ALT or CTRL, that were depressed when it<br />

occurred.<br />

Another major difference is that events in newer models propagate through the document<br />

hierarchy. In Netscape 4, events begin at the top of the hierarchy and ―trickle‖ down to the<br />

object at which they occurred, affording enclosing objects the opportunity to modify, cancel, or<br />

handle the event. Under Internet Explorer, events begin at the object where they occur and<br />

―bubble‖ up the hierarchy. Under DOM2, events can trickle down and bubble up, as shown<br />

here:<br />

Netscape 4 Event Model<br />

Netscape 4 implemented the first event model with advanced features not found in the basic<br />

event model. <strong>The</strong>se features permit somewhat greater flexibility with respect to how you handle<br />

events and where you can do so in document object hierarchy.<br />

Unfortunately, this model is ―dead‖ in the sense that it is found only in Netscape version 4<br />

browsers. Since Mozilla-based browsers adopted the DOM2 model and Netscape 6+ are based<br />

on Mozilla, this model is an evolutionary dead end. We present it here for those who need to<br />

ensure backward compatibility, and to provide insight into the historical influence it had on the<br />

DOM2 model.<br />

Event Objects<br />

When an event occurs in Netscape 4, the browser creates an Event object and passes it to the<br />

handler. Some interesting properties of Event objects are listed in Table 11-6.<br />

Table 11-6: Instance Properties of Netscape 4’s Event Object<br />

Property Description<br />

>data Array of strings containing the URLs of objects that were dragged and<br />

dropped.<br />

>modifiers Bitmask indicating which modifier keys were held down during the event.<br />

<strong>The</strong> bitmask is a bitwise combination of the constants: ALT_MASK,<br />

CONTROL_MASK, META_MASK, and SHIFT_MASK, which are static<br />

(class) properties of the Event object. For example, if the ALT and CTRL<br />

keys were depressed, modifiers will have value (Event.ALT_MASK &<br />

Event.CONTROL_MASK).<br />

>pageX Numeric value indicating the horizontal coordinate where the event<br />

occurred.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!