Ion Vasile Ion Vasile - 2 months ago 23
Javascript Question

dragDrop javascript function name reserved in Microsoft Edge?

Why if I use a

dragDrop
event function name in microsoft edge will not work?

Example:

<!DOCTYPE HTML>
<html>
<head>
<style>
#div1 {
width: 350px;
height: 70px;
padding: 10px;
border: 1px solid #aaaaaa;
}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function dragDrop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>

<p>Drag the W3Schools image into the rectangle:</p>

<div id="div1" ondrop="dragDrop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="img_logo.gif" draggable="true" ondragstart="drag(event)" width="336" height="69">

</body>
</html>


https://jsfiddle.net/f5pvu9h0/

Answer

Inside an inline event handler, the element's DOM object is in the scope chain.

Elements in Edge have a dragDrop() method, so you're calling that.

This is why you should never use inline event handlers.

Comments