dataTransfer³ª clipboardData °³Ã¼¸¦ ÅëÇÑ Å¬¸³º¸µå·Î ºÎÅÍ ÁöÁ¤µÈ ¾ç½ÄÀÇ µ¥ÀÌÅ͸¦ ¹ÝȯÇÑ´Ù.
Text | ÅؽºÆ®·Î µ¥ÀÌÅ͸¦ ¹ÝȯÇÑ´Ù. |
URL | ÁÖ¼Ò(URL)·Î µ¥ÀÌÅ͸¦ ¹ÝȯÇÑ´Ù. |
¹Ýȯ°ª sData´Â dataTransfer³ª clipboardData °³Ã¼¸¦ ÅëÇÑ Å¬¸³º¸µå(clipboard)·Î ºÎÅÍ µ¥ÀÌÅ͸¦ ÁöÁ¤µÈ ¾ç½ÄÀ¸·Î ¹ÝȯÇÏ´Â ¹®ÀÚ¿ÀÌ´Ù.
setData¿¡ Æ÷ÇÔµÈ Á¤º¸¿¡µû¶ó, ÀÌ °ªÀº À̹ÌÁö, ÅؽºÆ® ȤÀº ÁÖ¼Ò ¾ØÄ¿ÀÇ °æ·Î¸¦ ¹ÝȯÇÒ ¼ö ÀÖ´Ù.
getData ¸Þ¼µå´Â ÇÁ·¹ÀÓ°£ º¸¾ÈÀ» °ÈÇÏ°í, µ¿ÀÏÇÑ µµ¸ÞÀÎ(omain) ¼ÓÀ¸·ÎºÎÅ͸¸ µ¥ÀÌÅÍÀÇ Àü¼ÛÀ» Çã¿ëÇÑ´Ù.
»ç¿ëÀÚ°¡, ¿¹¸¦µé¾î HTTP¿Í HTTPS¿Í °°ÀÌ, ¼·Î ´Ù¸¥ º¸¾È ÇÁ·ÎÅäÄÝ(protocol) »çÀÌ¿¡¼ µå·¡±×(drag)ÇÏ¸é ½ÇÆÐµÉ °ÍÀÌ´Ù. ¶ÇÇÑ, µ¿ÀÏÇÑ ºê¶ó¿ìÀú¿¡¼, ¿¹¸¦µé¾î Çϳª´Â º¸Åë¼öÁØÀÌ°í ´Ù¸¥ Çϳª´Â ³ôÀº ¼öÁØÀÏ °æ¿ì¿Í °°ÀÌ ¼·Î º¸¾È ¼öÁØÀÌ ´Ù¸¥ µÎ ÀνºÅº½º »çÀÌ¿¡¼ µå·¡±×ÇÏ´Â °Íµµ ½ÇÆÐÇÒ °ÍÀÌ´Ù. ¶ÇÇÑ, MS Word¿Í °°ÀÌ ´Ù¸¥ µå·¡±×ÇÒ ¼ö ÀÖ´Â Àû¿ëÀ¸·ÎºÎÅÍ ºê¶ó¿ìÀú·Î µå·¡±×ÇÏ´Â °æ¿ìµµ ½ÇÆÐÇÒ °ÍÀÌ´Ù.
oncopy³ª oncut À̺¥Æ®¿¡¼, Ŭ¸³º¸µå·ÎºÎÅÍ µ¥ÀÌÅ͸¦ ¹Ýȯ¹Þ±â À§ÇÏ¿© getData ¸Þ¼µå¸¦ »ç¿ëÇϱâ À§Çì¼´Â, À̺¥Æ®Ã³¸®ÀÚ ½ºÅ©¸³Æ® ¼Ó¿¡ window.event.returnValue=falseÀ» ¼³Á¤ÇÏ¿©¾ß ÇÑ´Ù.
°³Ã¼ | script | IE |
---|
dataTransfer °³Ã¼¿¡¼ setData¿Í getData ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© ¹®ÀÚ¿À» µå·¡±×ÇÏ¿© »õ À§Ä¡¿¡ ³Ö´Â´Ù.
<HEAD> <SCRIPT> function beginDrag(){ event.dataTransfer.setData('Text',divA.innerText); } function endDrag(){ window.event.returnValue=false; divB.innerText=event.dataTransfer.getData('Text'); } function overDrag(){ window.event.returnValue=false; } </SCRIPT> </HEAD> <BODY> <DIV id="divA" ondragstart="beginDrag()" style="border:solid 1 blue;width:300">ÀÌ ¹®ÀÚ¿À» µå·¡±×ÇÏ¿©....</DIV> <DIV id="divB" ondragover="overDrag()" ondragenter="endDrag()" style="border:solid 1 red;width:300">¿©±â¿¡ ³õ¾Æº¸¶ó.</DIV> </BODY>
²ø¾î³õ±â(drag-and-drop)·Î getData ¸Þ¼µå·Î ÁÖ¼Ò¸¦ ¹ÝȯÇÑ´Ù.
<HEAD> <SCRIPT> function startDrag(){ event.dataTransfer.setData('URL',aObj.href); } function finishDrag(){ divC.innerText=event.dataTransfer.getData('URL'); divC.style.color='red'; divC.style.fontWeight='bold'; } </SCRIPT> </HEAD> <BODY> <DIV style="border:solid 1 blue;width:200"> <A id="aObj" href="http://koxo.com" onclick="return(false)" ondragstart="startDrag()">¿¹Á¦ ¾ØÄ¿ ¹®ÀÚ¿</A> </DIV> <DIV id=divC ondragenter="finishDrag()" style="border:solid 1 red;width:200">¿©±â¿¡ ²ø¾î ³õ¾Æº¸¶ó.</DIV> </BODY>