Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  124] [ 6]  / answers: 1 / hits: 16829  / 12 Years ago, fri, march 2, 2012, 12:00:00

I'm currently working on a project at work using the HTML5 Drag and Drop API to provide added functionality including dragging items in and out of browsers. I am currently coming across issues which are specific to Chrome (otherwise only tested in Firefox, which works as expected).

The issue is that I cannot use the event.dataTransfer.getData(type) method to return the data set on the dragstart event in any events except the drop event.

I set the event like so, after binding to the dragstart event (which DOES fire):

event.dataTransfer.setData('text/plain', "some string")

Then in the drop event, I can get the data fine.


However I cannot use the same method as above on any other events (such as dragover). Even if I try and use the above method on the line after calling setData() (i.e., in the dragstart callback), then it will still return undefined.

So, in Chrome, the issue is that getData in Chrome will always return undefined, except within the drop event callback. (In Firefox, I can successfully get the correct data.)

If you have the reference to the dataTransfer object of the same dragging element, then why should you not be able to get the data until it is dropped?

Just wondering:

  • Has anyone had this trouble with Chrome before?

  • What workarounds are there?

  • Or, is it something Chrome needs to fix?

Specification for HTML5 drag and drop.

More From » html


WebKit, and hence Chrome, is quite restrictive on when you can call getData. You're not allowed to do it inside dragstart or dragover. I think this is the canonical bug.

[#87082] Thursday, March 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 507
Total Questions: 103
Total Answers: 111

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago