Using some basic drag'n'drop features and i keep getting this message in Firefox, works well in Chrome though.
NoModificationAllowedError: Modifications are not allowed for this document
This happens when i try to use the clearData()
function on the event when the ondrop
event is fired.
HTML:
<!-- draggable element -->
<div draggable="true" ondragstart="onDragStart(event);">
<!-- dropzone element -->
<div ondragover="onDragOver(event);" ondragenter="onDragEnter(event);" ondrop="onDrop(event);"></div>
JS:
function onDragStart(event) {
event
.dataTransfer
.setData('text/plain', 'test');
}
function onDragOver(event) {
event.preventDefault();
}
function onDragEnter(event) {
event.preventDefault(); // polyfill fix
}
function onDrop(event) {
event.preventDefault();
event
.currentTarget
.parentNode
.classList.add("dropped");
event
.dataTransfer
.clearData(); //<---- This is where it fails
}
So yeah no idea how to fix this, and i need to clear the data as i set/reset some variable and internal params using it (code omitted). Works well in chrome (even IE)
DataTransfer.clearData()
: "This method can only be used in the handler for thedragstart
event, because that's the only time the drag operation's data store is writeable." – Trophy