323Chapter 15Generic HTML Element ObjectsEvent handlersonactivateonbeforedeactivateondeactivateCompatibility:WinIE5.5+, (Web design conference) MacIE-, NN-,
323Chapter 15Generic HTML Element ObjectsEvent handlersonactivateonbeforedeactivateondeactivateCompatibility:WinIE5.5+, MacIE-, NN-, Moz-, Safari- The onactivateand ondeactivateevent handlers are very similar to the onfocusandonblurevent handlers, respectively. If an element receives focus, the onactivateevent firesfor that element just before the onfocusevent fires; conversely, just prior to the element los- ing focus, events fire in the sequence onbeforedeactivate, ondeactivate, onblur. Onlyelements that, by their nature, can accept focus (for example, links and form input controls) or that have a tabindexattribute set can become the active element (and therefore fire theseevents). WinIE5.5+ maintains the original onfocusand onblurevent handlers. But because the behav- iors are so close to those of the onactivateand ondeactivateevents, I don t recommendmixing the old and new event handler names in your coding style. If you script exclusively forWinIE5.5+, you can use the new terminology throughout. ExampleYou can modify Listing 15-34 later in this chapter by substituting onactivatefor onfocusand ondeactivatefor onblur. Use The Evaluator (Chapter 13) to experiment with the onbeforedeactivateevent handler. To begin, set the myPelement so it can accept focus: myP.tabIndex = 1If you repeatedly press the Tab key, the myPparagraph will eventually receive focus indicatedby the dotted rectangle around it. To see how you can prevent the element from losing focus, assign an anonymous function to the onbeforedeactivateevent handler, as shown in the fol- lowing statement: myP.onbeforedeactivate = new Function( event.returnValue=false ) Now you can press Tab all you like or click other focusable elements all you like, and themyPelement will not lose focus until you reload the page (which clears away the event han- dler). Please do not do this on your pages unless you want to infuriate and alienate yoursitevisitors. Related Items:onblur, onfocusevent handlers. onbeforecopyCompatibility:WinIE5+, MacIE-, NN-, Moz-, Safari- The onbeforecopyevent handler fires before the actual copy action takes place wheneverthe user initiates a content copy action via the Edit menu (including the Ctrl+C keyboardshortcut) or the right-click context menu. If the user accesses the Copy command via the Editor context menu, the onbeforecopyevent fires before either menu displays. In practice, theevent may fire twice even though you expect it only once. Just because the onbeforecopyevent fires, it does not guarantee that a user will complete the copy operation (for example, the context menu may close before the user makes a selection). Unlike paste-related events, the onbeforecopyevent handler does not work with form inputelements. Just about any other HTML element is fair game, however. elementObject.onbeforecopy