Source code
Revision control
Copy as Markdown
Other Tools
<?xml version="1.0" encoding="utf-8"?>
<head>
<title>Canvas drag and drop: helper file</title>
<script type="application/ecmascript">
function paint(color)
{var canvas = document.querySelector('canvas'),
c = canvas.getContext('2d');
c.fillStyle = color;
c.beginPath();
c.moveTo(0,0);
c.lineTo(100,0);
c.lineTo(100,100);
c.lineTo(0,100);
c.closePath();
c.fill();}
function start(event)
{event.dataTransfer.effectAllowed = 'copy';
event.dataTransfer.setData('text/plain', 'green');}
</script>
</head>
<body onload="paint('gray')">
<p>
<canvas width="100" height="100" ondragenter="event.preventDefault()" ondragover="return false" ondrop="paint(event.dataTransfer.getData('text/plain'))">Canvas</canvas>
</p>
</body>
</html>