I am creating dropzone component for custom elements (with draggable
attribute) and I would need to share data between dragstart
and dragenter
event handlers. My first attempt was:
// Set data when dragging begins
draggableElement.addEventListener("dragstart", e => e.setData("text/plain", "someCustomData"))
// Get data when user enters dropzone
dropzoneElement.addEventListener("dragenter", e => console.log(e.getData("text/plain")))
Unfortunately, this approach does not work (data are always empty), because getData
can be used only in drop
event handler due to security reason. So, is there any way how to share data between dragstart
and dragenter
?
Also, I can’t use a global variable, because I would need to make dragging across several iframes (all with my web app). I would need data to be part od the drag event.