305Chapter 15Generic HTML Element ObjectsWhen (Anonymous web server) a user clicks
Monday, December 17th, 2007305Chapter 15Generic HTML Element ObjectsWhen a user clicks the mouse button, different things happen depending on whether eventcapture is enabled. Without event capture, the clickevent bubbles up from wherever itoccurred to the onclickevent handler in the bodyelement. (An alert dialog box displays tolet you know when the event reaches the body.) But with event capture turned on (the con- text menu is showing), the handleClick()event handler takes over to apply the desiredchoice whenever the click is atop one of the context menu items. For all clickevents han- dled by this function, the context menu is hidden and the clickevent is cancelled from bub- bling up any higher (no alert dialog box appears). This takes place whether the user makes achoice in the context menu or clicks anywhere else on the page. In the latter case, all youneed is for the context menu to go away like the real context menu does. For added insur- ance, the onlosecaptureevent handler hides the context menu when a user performs any ofthe actions just listed that cancel capture. Listing 15-30: Using setCapture() and releaseCapture()
mergeAttributes() Method