15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

122<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

elementObject.onPaste<br />

Listing 15-45: Using onBeforePaste and onPaste Event<br />

Handlers<br />

<br />

<br />

onBeforePaste and onPaste Event Handlers<br />

<br />

TD {text-align:center}<br />

TH {text-decoration:underline}<br />

.blanks {text-decoration:underline}<br />

<br />

<br />

function selectWhole() {<br />

var obj = window.event.srcElement<br />

var range = document.body.createTextRange()<br />

range.moveToElementText(obj)<br />

range.select()<br />

event.returnValue = false<br />

}<br />

function handleCopy() {<br />

var rng = document.selection.createRange()<br />

clipboardData.setData(“Text”,rng.text)<br />

event.returnValue = false<br />

}<br />

function handlePaste() {<br />

var elem = window.event.srcElement<br />

if (elem.className == “blanks”) {<br />

elem.innerHTML = clipboardData.getData(“Text”)<br />

}<br />

event.returnValue = false<br />

}<br />

function handleBeforePaste() {<br />

var elem = window.event.srcElement<br />

if (elem.className == “blanks”) {<br />

event.returnValue = false<br />

}<br />

}<br />

<br />

<br />

<br />

onBeforePaste and onPaste Event Handlers<br />

<br />

Your goal is to copy and paste one noun and one<br />

adjective from the following table into the blanks<br />

of the sentence. Select a word from the table and<br />

copy it to the clipboard. Select one or more spaces<br />

of the blanks in the sentence and choose Paste to<br />

replace the blank with the clipboard contents.<br />

<br />

NounsAdjectives

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

Saved successfully!

Ooh no, something went wrong!