20 February 2019
tags:
HTML5 drag and drop API They are useful in creating an intuitive UI. But there are some pitfalls
event.dataTransfercan only be setondragstart, and cannot be read untilondrop(SO post). This is a security minded feature, as drag n drop is a feature that can potentially be cross browser/cross application (think drop file interface on browsers). Allowingondragenteretc handlers sniff transferData is a bad idea.- in order for
ondropevent to be called,ondragenterandondragovermust both be cancelled (byev.preventDefault()orreturn false) (MDN). Most dom elements are not droppable. This ensures that on drop event only fires when the developer explicitly enables it.