What is the difference between
event.originalEvent.dataTransfer.files
and
event.dataTransfer.files
???
Because in drag and drop , second code does not work and it is undefined and i had to use first code because it works !
jQuery does not pass the browser event object to you, it passes the jQuery event object. You can access the original untouched event object by the .originalEvent
property in the jQuery event object. Then you can proceed as normal.
So in code:
jQuery event model:
$(document).on("drop dragend dragstart dragenter dragleave drag dragover", function(event) {
event.preventDefault();
if (event.type === "drop") {
alert(event.originalEvent.dataTransfer.files);
}
});
W3C event model:
function preventDefault(event) {
event.preventDefault();
}
function alertFiles(event) {
alert(event.dataTransfer.files);
}
document.addEventListener("dragstart", preventDefault, false);
document.addEventListener("dragenter", preventDefault, false);
document.addEventListener("dragleave", preventDefault, false);
document.addEventListener("drag", preventDefault, false);
document.addEventListener("dragend", preventDefault, false);
document.addEventListener("dragover", preventDefault, false);
document.addEventListener("drop", preventDefault, false);
document.addEventListener("drop", alertFiles, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With