Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="../resources/test-helper.js"></script>
<head>
<title>Object with image drag and drop</title>
<style type="text/css">
div[ondragenter]
{width:105px;
min-height:105px;
text-align:center;
margin-top:20px;
padding:10px;
border:solid thin navy;}
p:first-child
{padding-left:12px;}
</style>
<script type="application/ecmascript">
function addImage(event)
{var c = document.createElement('img');
c.setAttribute('src',event.dataTransfer.getData('text/uri-list').replace(/\r\n$/,''));
document.querySelector('div').appendChild(c);}
function start(event)
{event.dataTransfer.effectAllowed = 'copy';
event.dataTransfer.setData('text/uri-list', document.querySelector('object').getAttribute('data'));}
</script>
</head>
<body>
<p><object draggable="true" ondragstart="start(event)" type="image/png" data="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAEq0lEQVR42u1dvU4bQRAeR0RCCilSp0peIoKGB4DSXYRDlcZlFClKBI4bB/kV/AymIDwCTahiicaioEOxhCsjWVTJziyKMfYZn+9ud3bvG2mEZB13u9+nndmf2Rki7fKFXtEBbVKD9o22jB4bPaND6hm9Mjo0enevw/vfevKMfbYl/8vv4HdBUkvFALhltG2A7dN3+pur8jv53fwN/hZkjjRo3eiuAatjdJA7CcnkDOSb/G1uQ6mFzUeDagaQrvl764yEJOU22LbUymXaGrRhOt40OvJOQvLIGUkbP9GLeIn4SM9NJ+tOTVI+Jq0ubY9sVFRNxy6DIWKWmEvpQ/ByQNumI+fBEjHrZ86lT8HJV3ptGn8aDRGzxJxKHwMZFe9Mg6+jJWNCyrX0VbUc0nuj4+jJmPiWsfRZodN+ZvSoNETMjpYjwUCFfKaXpjEnpSVjQsqJYOF5ZLw1elF6MiakXAgmnpw378DegIgZUm4EGw8jA2QsIuUbvXHpM2CmljFfhfsUO5uCA0/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ErkJggg==" alt="PNG circle">PNG image</object></p>
<p>Drag circle above to the box below. It should be copied to the box once you drop it there.</p>
<div
ondragenter="event.preventDefault()"
ondragover="return false"
/>
</body>
<script>
async function test() {
const object = document.querySelector('object');
const div = document.querySelector('div');
function onDropCallBack(event) {
addImage(event);
assert_equals(object.getAttribute('data'), event.dataTransfer.getData('text/uri-list').replace(/\r\n$/,''));
return true;
}
dragDropTest(object, div, onDropCallBack, 'Dragging the object to the bottom div should copy the image there');
}
test();
</script>
</html>