325Chapter 15Generic HTML Element Objectsguarantee that a (Business web site) user
325Chapter 15Generic HTML Element Objectsguarantee that a user will complete the cut operation (for example, the context menu may closebefore the user makes a selection). If you add the onbeforecutevent handler to an HTML ele- ment, the context menu usually disables the Cut menu item. But assigning a JavaScript call tothis event handler brings the Cut menu item to life. ExampleYou can use the onbeforecutevent handler to preprocess information prior to an actual cutaction. You can try this by editing a copy of Listing 15-33, changing the onbeforecopyeventhandler to onbeforecut. Notice that in its original form, the example does not activate the Cutitem in either the context or Edit menu when you select some text in the second paragraph. Butby assigning a function to the onbeforecutevent handler, the menu item is active, and theentire paragraph is selected from the function that is invoked. Related Items:onbeforecopy, oncutevent handlers. onbeforedeactivateCompatibility:WinIE5.5+, MacIE-, NN-, Moz-, Safari- (See onactivateevent handler) onbeforeeditfocusCompatibility:WinIE5+, MacIE-, NN-, Moz-, Safari- The onbeforeeditfocusevent handler is triggered whenever you edit an element on a pagein an environment such as Microsoft s DHTML Editing ActiveX control or with the editablepage content feature of IE5.5+. This discussion focuses on the latter scenario because it isentirely within the scope of client-side JavaScript. The onbeforeeditfocusevent fires justbefore the element receives its focus. (There may be no onscreen feedback that editing isturned on unless you script it yourself.) The event fires each time a user clicks the element, even if the element just received edit focus elsewhere in the same element. ExampleUse The Evaluator (Chapter 13) to explore the onbeforeeditfocusin WinIE5.5+. In the fol- lowing sequence, you assign an anonymous function to the onbeforeeditfocusevent han- dler of the myPelement. The function turns the text color of the element to red when theevent handler fires: myP.onbeforeeditfocus = new Function( myP.style.color= red ) Now turn on content editing for the myPelement: myP.contentEditable = trueIf you now click inside the myPelement on the page to edit its content, the text turns to redbefore you begin editing. In a page scripted for this kind of user interface, you would includesome control that turns off editing and changes the color to normal. Related Items:document.designMode, contentEditable, isContentEditableproperties. onbeforepasteCompatibility:WinIE5+, MacIE-, NN-, Moz-, Safari- Like onbeforecopyand onbeforecut, the onbeforepasteevent occurs just prior to the dis- play of either the context or menu bar Edit menu when the current object is selected (or has aselection within it). The primary value of this event comes when you use scripts to control theelementObject.onbeforepaste