001.xhtml (1333B)
1 <?xml version="1.0" encoding="utf-8"?> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Reload during canvas drag and drop roundtrip</title> 5 <style type="text/css"> 6 img 7 {margin:0 2px;} 8 </style> 9 <script type="application/ecmascript"> 10 function addImage(event) 11 {var c = document.createElement('img'); 12 c.setAttribute('src',event.dataTransfer.getData('text/uri-list').replace(/\r\n$/,'')); 13 document.querySelector('p').appendChild(c);} 14 function start(event) 15 {event.dataTransfer.effectAllowed = 'copy'; 16 event.dataTransfer.setData('text/uri-list', document.querySelector('canvas').toDataURL('image/png')); 17 window.location.reload();} 18 </script> 19 </head> 20 <body> 21 <p> 22 <canvas width="100" height="100" draggable="true" ondragstart="start(event)" ondragenter="event.preventDefault()" ondragover="return false" ondrop="addImage(event)">Canvas</canvas> 23 </p> 24 <p>Drag canvas pattern around page and then drag it back and drop on itself. It should be duplicated once you drop it.</p> 25 <script type="application/ecmascript"> 26 var canvas = document.querySelector('canvas'), 27 c = canvas.getContext('2d'); 28 for(var x = 0; x != 50; x++) 29 {c.fillStyle = (x%2 == 0)?'navy':'white'; 30 c.beginPath(); 31 c.moveTo(x,x); 32 c.lineTo(100-x,x); 33 c.lineTo(100-x,100-x); 34 c.lineTo(x,100-x); 35 c.closePath(); 36 c.fill();} 37 </script> 38 </body> 39 </html>