Java Reference
In-Depth Information
➤
You learned about the standard
Event
object and how it provides a lot of information about
the event that occurred, including the type of event and the element that received the event.
➤
You learned about old‐IE's proprietary event model, how to connect events with
attachEvent()
, and how to access old‐IE's
event
object.
➤
Some differences exist between the standard DOM event model and the old‐IE event model.
You learned the key differences and wrote a simple cross‐browser event utility.
➤
Some events have a default action that occurs when the event fires, and you can prevent
that action with the standard
Event
object's
preventDefault()
method and old‐IE's
returnValue
property.
➤
Modern browsers support native drag‐and‐drop capabilities, and you can write code that
takes advantage of this new feature.
➤
In some instances, such as for the
document
object, a second way of connecting event han-
dlers to code is necessary. Setting the object's property with the name of the event handler to
your function produces the same effect as if you did it using the event handler as an attribute.
➤
In some instances, returning values from event functions enables you to cancel the action
associated with the event. For example, to stop a clicked link from navigating to a page, you
return
false
from the event handler's code.
That's it for this chapter. In the next chapter, you move on to form scripting, where you can add
various controls to your page to help you gather information from the user.
exerCises
You can find suggested solutions to these questions in Appendix A.
1.
Add a method to the event utility object called
isOldIE()
that returns a boolean value
indicating whether or not the browser is old‐IE.
2.
Example 15 exhibits some behavior inconsistencies between standards‐compliant browsers
and old‐IE. Remember that the event handlers execute in reverse order in old‐IE. Modify this
example to use the new
isOldIE()
method so that you can write specific code for old‐IE and
standards‐compliant browsers (Hint: you will call the
addListener()
method four times).
3.
Example 17 had you write a cross‐browser tab script, but as you probably noticed, it behaves
peculiarly. The basic idea is there, but the tabs remain active as you click another tab. Modify
the script so that only one tab is active at a time.