Java Reference
In-Depth Information
alert("This link is going nowhere");
e.returnValue = false;
}
link.attachEvent("onclick", linkClick);
</script>
</body>
</html>
Save this as ch10 _ example10.html .
Let's first look at the call to attachEvent() . The overall pattern is the same as addEventListener()
(and thus removeEventListener() ); you pass the event you want to listen for and the function to execute
when the event occurs. But as you'll notice from this code, the event names are prefixed with “ on ”.
The second argument is the function that executes when the event occurs. Notice, though, that
the linkClick() function defines a parameter called e . When you register an event handler with
attachEvent() , old‐IE passes the event object to the handling function.
Also notice that linkClick() does not return false or call preventDefault() . Instead, old‐IE's
event object has a property called returnValue , and setting it to false achieves the same result.
using event data
Unsurprisingly, IE's event object provides some different properties from the DOM standard's
Event and MouseEvent objects, although they typically provide you with similar data.
The following table lists some of the properties of IE's event object.
properties of the
event objeCt
desCription
Indicates whether the Alt key was pressed when the event was
generated
altKey
Indicates which button on the mouse was pressed
button
Gets or sets whether the current event should bubble up the
hierarchy of event handlers
cancelBubble
Indicates where in the browser window, in horizontal coordinates,
the mouse pointer was when the event was generated
clientX
Indicates where in the browser window, in vertical coordinates, the
mouse pointer was when the event was generated
clientY
Indicates whether the Ctrl key was pressed when the event was
generated
ctrlKey
Gets the element object the mouse pointer is exiting
fromElement
 
Search WWH ::




Custom Search