15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1 ✦ Generic HTML Element Objects (Chapter 15)<br />

I pledge allegiance to the<br />

flag<br />

of the United States of<br />

America, and to the Republic for which it stands, one nation under<br />

God, indivisible, with liberty and justice for all.<br />

<br />

<br />

onPaste<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓<br />

Example<br />

Listing 15-45 demonstrates how to use the onBeforePaste and onPaste event<br />

handlers (in conjunction with onBeforeCopy and onCopy) to let scripts control the<br />

data transfer process during a copy-and-paste user operation. A table contains<br />

words to be copied (one column of nouns, one column of adjectives) and then<br />

pasted into blanks in a paragraph. The onBeforeCopy and onCopy event handlers<br />

are assigned to the TABLE element because the events from the TD elements bubble<br />

up to the TABLE container and there is less HTML code to contend with.<br />

Inside the paragraph, two SPAN elements contain underscored blanks. To paste<br />

text into the blanks, the user must first select at least one character of the blanks.<br />

(See Listing 15-37, which gives a drag-and-drop version of this application.) The<br />

onBeforePaste event handler in the paragraph (which gets the event as it bubbles<br />

up from either SPAN) sets the event.returnValue property to false, thus allowing<br />

the Paste item to appear in the context and Edit menus (not a normal occurrence<br />

in HTML body content).<br />

At paste time, the innerHTML property of the target SPAN is set to the text data<br />

stored in the clipboard. The event.returnValue property is set to false here, as<br />

well, to prevent normal system pasting from interfering with the controlled version.<br />

121<br />

elementObject.onPaste

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!