326Part IIIDocument Objects Referencecopy-and-paste process of (My web site) a complex
326Part IIIDocument Objects Referencecopy-and-paste process of a complex object. Such an object may have multiple kinds of dataassociated with it, but your script captures only one of the data types. Or, you may want to putsome related data about the copied item (for example, the idproperty of the element) into theclipboard. By using the onbeforepasteevent handler to set the event.returnValuepropertyto false, you guarantee that the pasted item is enabled in the context or Edit menu (providedthe clipboard is holding some content). A handler invoked by onpasteshould then apply thespecific data subset from the clipboard to the currently selected item. ExampleSee Listing 15-45 for the onpasteevent handler (later in this chapter) to see how the onbe- forepasteand onpasteevent handlers work together. Related Items:oncopy, oncut, onpasteevent handlers. onblurCompatibility:WinIE3+, MacIE3+, NN2+, Moz1+, Safari1+ The onblurevent fires when an element that has focus is about to lose focus because someother element is about to receive focus. For example, a text input element fires the onblurevent when a user tabs from that element to the next one inside a form. The onblurevent ofthe first element fires before the onfocusevent of the next element. The availability of the onblurevent has expanded with succeeding generations of script- capable browsers. In the earlier versions, blur and focus were largely confined to text-orientedinput elements (including the selectelement). These are safe to use with all scriptablebrowser versions. The windowobject received the onblurevent handler starting with NN3 andIE4. IE4 also extended the event handler to more form elements, predominantly on the Windowsoperating system because that OS has a user interface clue (the dotted rectangle) when itemssuch as buttons and links receive focus (so that you may act upon them by pressing the key- board s spacebar). For IE5+, the onblurevent handler is available to virtually every HTML ele- ment. For most of those elements, however, blur and focus are not possible unless you assign avalue to the tabindexattribute of the element s tag. For example, if you assign tabindex= 1 inside a
tag, the user can bring focus to that paragraph (highlighted with the dotted rectan- gle in Windows) by clicking the paragraph or pressing the Tab key until that item receives focusin sequence. If you plan to use the onblurevent handler on window or text-oriented input elements, beaware that there might be some unexpected and undesirable consequences of scripting forthe event. For example, in IE, a windowobject that has focus loses focus (and triggers theonblurevent) if the user brings focus to any element on the page (or even clicks a blank areaon the page). Similarly, the interaction between onblur, onfocus, and the alert()dialogbox can be problematic with text input elements. This is why I generally recommend usingthe onchangeevent handler to trigger form validation routines. If you should employ boththe onblurand onchangeevent handler for the same element, the onchangeevent firesbefore onblur. For more details about using this event handler for data validation, seeChapter 43 on the CD-ROM. WinIE5.5+ adds the ondeactivateevent handler, which fires immediately before theonblurevent handler. Both the onblurand ondeactivateevents can be blocked if theonbeforedeactivateevent handler function sets event.returnValueto false. ExampleMore often than not, a page author uses the onblurevent handler to exert extreme controlover the user, such as preventing a user from exiting out of a text box unless that user typeselementObject.onbeforepaste