Im programming an upload website and I want to drag and drop files to upload them. Currently Im showing a prompt for the user to drop their file if he is at the right location. The problem is that also other stuff like marked text triggers the prompt. How can I check if the dragenter is with a file ?
Im using the following code:
$(document).on({
dragenter: () => {
//Only start new upload if old is completed
if (!this.uploadWindowOpen) {
$("#drop-prompt-background").fadeIn()
$("#drop-prompt-path").text(Browser.getCurrentPath().toString())
}
},
dragleave: () => {
$("#drop-prompt-background").fadeOut()
},
drop: event => {
event.preventDefault()
$("#drop-prompt-background").hide()
let file = event.originalEvent?.dataTransfer?.files[0]
if (file) this.startUpload(file)
},
dragover: event => {
//No file open in new tab
event.preventDefault()
}
})
Aucun commentaire:
Enregistrer un commentaire