Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has Chrome improperly implemented the dataTransfer object?

When I do this in dragstart event:

e.dataTransfer.setData('text/plain', 'text');
e.dataTransfer.setData('text/html', 'html');
e.dataTransfer.setData('application/x-bookmark', 'bookmark');

and this in drop event:

for (var i = 0; i < e.dataTransfer.types.length; i++) {
   var type = e.dataTransfer.types[i];
   console.log(type + ":" + e.dataTransfer.getData(type));
}

I was supposed to have:

text/plain:text
text/html:html
application/x-bookmark:bookmark

as what I got in FF, but actually I got:

Text:text
text/plain:text

in Chrome. Where are those data gone? Does this mean chrome did not implement the dataTransfer object properly? And what can I do about this?

I ran this in Chrome 4.0.266.0

like image 867
Shinjikun Avatar asked Dec 13 '09 08:12

Shinjikun


People also ask

How do you initialize a DataTransfer object?

The DataTransfer() constructor, when invoked, must return a newly created DataTransfer object initialized as follows: Set the drag data store's item list to be an empty list. Set the drag data store's mode to read/write mode. Set the dropEffect and effectAllowed to "none".

Which of the following is correct way to set the dragged data?

setData() method sets the drag operation's drag data to the specified data and type. If data for the given type does not exist, it is added at the end of the drag data store, such that the last item in the types list will be the new type.

What is DataTransfer in Javascript?

The DataTransfer object is used to hold the data that is being dragged during a drag and drop operation. It may hold one or more data items, each of one or more data types. For more information about drag and drop, see HTML Drag and Drop API. This object is available from the dataTransfer property of all drag events .


1 Answers

Yes it is a bug in Chrome. See issues 31037 and issue 30240 in the chromium issue tracker (chromium is the open source version of google chrome). I see no other solution than waiting for the bug to be fixed. You can help them fixing it by providing a simple test case.

like image 96
Fabian Jakobs Avatar answered Oct 19 '22 15:10

Fabian Jakobs