clipboardData °³Ã¼¿¡¼ setData¿Í getData ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ¿À¸¥ÂÊ ¸¶¿ì½º¸¦ Ŭ¸¯ÇßÀ» ¶§ ³ªÅ¸³ª´Â ¸Þ´º¸¦ ÀÌ¿ëÇÏ¿© À߶󳻱â¿Í ºÙ¿©³Ö±â¸¦ ¼öÇàÇÑ´Ù.
<HTML> <HEAD> <SCRIPT> var bResult; function fnLoad() { // Àß¶ó³¾ ÅؽºÆ®¸¦ ¼±ÅÃÇÑ´Ù. À߶󳻱⠼±Åà ÅؽºÆ® µÚÀÇ °ø°£µéÀº À߶󳻱⠺ÒÈ°¼ºÈµÈä·Î À¯ÁöµÈ´Ù. var txRange = document.body.createTextRange(); txRange.findText(oSource.innerText); txRange.select(); } function fnBeforeCut() { // µðÆúÆ®·Î À߶󳻱Ⱑ ºÒÈ°¼ºµÇ¾î ÀÖ´Â(event.returnValue=true) °ÍÀ» À߶󳻱Ⱑ °¡´ÉÇÏ°Ô ÇÑ´Ù. // À߶󳻱Ⱑ °¡´ÉÇØ Áö¸é ÀͽºÇ÷η¯´Â ÀÚµ¿ÀûÀ¸·Î Ŭ¸³º¸µå µ¥ÀÌÅ͸¦ º¹»çÇÏ°í ¼±ÅÃµÈ ÅؽºÆ®¸¦ ¹®¼¿¡¼ Á¦°ÅÇÑ´Ù. event.returnValue = false; } function fnCut(){ // window.clipboardData °³Ã¼ÀÇ ÅؽºÆ® ¾ç½Ä¿¡ µ¥ÀÌÅ͸¦ ÇÒ´çÇÏ°í, setData ºÎ¿ï°ª °á°ú¸¦ µð½ºÇ÷¹ÀÌÇÑ´Ù. event.returnValue = false; bResult = window.clipboardData.setData('Text',oSource.innerText); oSource.innerText = ''; tText.innerText += bResult; dataText.innerText=window.clipboardData.getData('Text'); } function fnBeforePaste() { // DIV¿¡¼ ºÙ¿©³Ö±â°¡ °¡´ÉÇÏ°Ô ÇÑ´Ù.ºÙ¿©³Ö±â´Â µðÆúÆ® true·Î ÁßÁöµÇ¾î ÀÖ´Ù. event.returnValue = false; } function fnPaste() { // µðÆúÆ® ºñÇìÀ̹ö·Î ÅؽºÆ® ÀԷ¿¡¼ onpasteÀÇ ¹Ýȯ°ªÀ» Ãë¼ÒÇÑ´Ù, event.returnValue = false; oTarget.innerText = window.clipboardData.getData('Text'); } </SCRIPT> <STYLE> .source {border:solid 1 red;color:brown;padding:5;background-color:ffa;width:300} .target {border:solid 1 blue;color:blue;padding:5;background-color:aff;width:300} </STYLE> </HEAD> <BODY onload="fnLoad()"> <DIV class="source" id="oSource" onbeforecut="fnBeforeCut()" oncut="fnCut()">ÀÌ ÅؽºÆ®¸¦ ¼±ÅÃÇؼ À߶󳻶ó.</DIV> <DIV class="target" id="oTarget" onbeforepaste="fnBeforePaste()" onpaste="fnPaste()">Àß¶ó³½ ÅؽºÆ®¸¦ ¿©±â ºÙ¿©³Ö¾î¶ó.</DIV> <DIV>setData °á°ú : <SPAN id="tText" style=color:blue> </SPAN><BR> clipboardData : <SPAN id=dataText style=color:green> </SPAN></DIV> </BODY> </HTML>