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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

outeEvent(event) Passes the Event instance event along normally down the object hierarchy<br />

for processing. This method is used by a Layer, Window, or Document to elect not to handle<br />

the specific event. For example, if the event was captured and after examination determined<br />

not to be of interest, this method is invoked to pass the event on down the hierarchy for<br />

(possibly) other handlers to process. Supported in N4+ (<strong>JavaScript</strong> 1.2+).<br />

DOM2 Event Methods<br />

<strong>The</strong> following methods are common to many (if not all) nodes under the DOM. <strong>The</strong> full<br />

specification can be found at http://www.w3.org/DOM/.<br />

addEventListener(whichEvent, handler, direction) Instructs the object to execute function<br />

handler when an event of the type given in the string whichEvent (for example, "click") occurs.<br />

<strong>The</strong> direction parameter is a Boolean indicating whether the handler should be fired in the<br />

capture phase (true) or bubbling phase (false). Multiple handlers for the same event can be<br />

attached by using this method multiple times. Listeners (event handlers) can be bound to text<br />

nodes as well as element nodes. Supported in N6+ (<strong>JavaScript</strong> 1.5+), DOM2.<br />

dispatchEvent(event) Causes the Event instance event to be processed by the appropriate<br />

handler of the object that this function was invoked as a method of. This method returns false if<br />

any handler that eventually processes the event returns false or invokes preventDefault(). <strong>The</strong><br />

node at which this method was invoked becomes the new target of event. This method is used<br />

to redirect an event to another node in the tree. Supported in N6+ (<strong>JavaScript</strong> 1.5+), DOM2.<br />

preventDefault() When invoked in a handler this method has the effect of canceling the default<br />

action associated with the event. Calling this method is the same as returning false from a<br />

handler. Note that in DOM2 once a handler has returned false or invoked this method, the<br />

default action associated with the event will not occur, no matter what value other handlers that<br />

process the event return. Supported in N6+ (<strong>JavaScript</strong> 1.5+), DOM2.<br />

removeEventListener(whichEvent, handler, direction) Removes the function handler as a<br />

handler for the event given in the string whichEvent (for example, "click") for the phase given by<br />

the Boolean direction. Note that direction must correspond to the value passed as the third<br />

parameter to addEventListener() when the handler was originally attached to the object.<br />

Supported in N6+ (<strong>JavaScript</strong> 1.5+), DOM2.<br />

stopPropagation() When invoked in an event handler, halts the normal propagation of the<br />

event after the current handler completes execution. This method works only for those events<br />

that are cancelable. Supported in N6+ (<strong>JavaScript</strong> 1.5+), DOM2.<br />

Notes<br />

You can set most properties of Event instances in Netscape if you have the<br />

UniversalBrowserWrite privilege (see Chapter 22). Also, most IE properties listed above are<br />

read-only in IE4, but mutable in IE5+.<br />

Event Handlers<br />

Event handlers are <strong>JavaScript</strong> code that are associated with an object and that ―fire‖ in<br />

response to a user or system event on that object. Document objects typically support<br />

numerous event handlers encompassing a wide range of user actions in addition to intrinsic or<br />

system events that occur in response to a browser or DOM event such as the page completing<br />

loading. Some browser objects, most notably Window, also support a variety of handlers that<br />

allow it to process events for any document it contains, for example, if the window is made up<br />

of multiple frames.<br />

HTML 4 Events<br />

<strong>The</strong> standard HTML 4 events are listed here. According to the event model of Internet Explorer<br />

4+, some events may be canceled and some events bubble up the hierarchy. <strong>The</strong> behavior of<br />

each of the HTML 4 events under Internet Explorer 4+ is indicated along with its associated<br />

handler (for example, the behavior of the blur event is given with the onblur handler).

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

Saved successfully!

Ooh no, something went wrong!