349Chapter 15Generic HTML Element ObjectsThe onlosecaptureevent handler fires (Web hosting comparison)
349Chapter 15Generic HTML Element ObjectsThe onlosecaptureevent handler fires whenever an object that has event capture turned onno longer has that capture. Event capture is automatically disengaged when the user per- forms any of the following actions: .Gives focus to any other window .Displays any system modal dialog box (for example, alert window) .Scrolls the page .Opens a browser context menu (right-clicking) .Tabs to give focus to the Address field in the browser windowA function associated with the onlosecaptureevent handler should perform any cleanup ofthe environment due to an object no longer capturing mouse events. ExampleSee Listing 15-30 earlier in this chapter for an example of how to use onlosecapturewith anevent-capturing scenario for displaying a context menu. The onlosecaptureevent handlerhides the context menu when the user performs any action that causes the menu to losemouse capture. Related Items:releaseCapture(), setCapture()methods. onmousedownonmouseupCompatibility:WinIE4+, MacIE4+, NN4+, Moz1+, Safari1+ The onmousedownevent handler fires when the user presses any button of a mouse. Theonmouseupevent handler fires when the user releases the mouse button, provided the objectreceiving the event also received an onmousedownevent. When a user performs a typical click of the mouse button atop an object, mouse events occur in the following sequence: onmousedown, onmouseup, onclick. But if the user presses the mouse atop an object andthen slides the cursor away from the object, only the onmousedownevent fires. These events enable authors and designers to add more application-like behavior to imagesthat act as action or icon buttons. If you notice the way most buttons work, the appearance ofthe button changes while you press the mouse button and reverts to its original style whenyou release the mouse button (or you drag the cursor out of the button). These events enableyou to emulate that behavior. The event object created with every mouse button action has a property that reveals whichmouse button the user pressed. NN4 s event model calls that property the whichproperty. IE4+ and NN6+/Moz1+ call it the buttonproperty (but with different values for the buttons). It ismost reliable to test for the mouse button number on either the onmousedownor onmouseupevent, rather than on onclick. The onclickevent object does not always contain the buttoninformation. ExampleTo demonstrate a likely scenario of changing button images in response to rolling atop animage, pressing down on it, releasing the mouse button, and rolling away from the image, Listing 15-42 presents a pair of small navigation buttons (left- and right-arrow buttons). Becausethe image object is not part of the document object model for NN2 or IE3 (which reports itselfas Navigator version 2), the page is designed to accept all browsers. Only those browsers thatsupport precached images and image swapping (and thus pass the test for the presence of theelementObject.onmousedown