---
created_at: '2014-07-29T11:49:04.000Z'
title: The HTML5 drag and drop disaster (2009)
url: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html
author: striking
points: 95
story_text: ''
comment_text: 
num_comments: 72
story_id: 
story_title: 
story_url: 
parent_id: 
created_at_i: 1406634544
_tags:
- story
- author_striking
- story_8101717
objectID: '8101717'

---
[Source](http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html "Permalink to The HTML5 drag and drop disaster - QuirksBlog")

# The HTML5 drag and drop disaster - QuirksBlog

## The HTML5 drag and drop disaster

After spending about a day and a half in testing I am forced to conclude that the [HTML5 drag and drop module][1] is not just a disaster, it’s a _fucking_ disaster.

The module should be removed from the HTML5 specification straight away, and conforming browsers should disable it at their earliest opportunity pending a complete rewrite from the ground up.

Web developers MUST NOT (in the sense of RFC 2119) use HTML 5 drag and drop. They should use [old-school scripts][2] instead.

Before we continue I’d like to say that in general I thoroughly approve of the HTML5 specification. Exactly _because_ the spec has such an overall quality I was so surprised (and, frankly, a bit confused and hurt) to find drag and drop a steaming pile of bovine manure.

In fact, it’s so outrageously bad that I’ve gone on strike. I refuse to do any more research on drag and drop. Go do it yourself. Or don’t bother. Whatever. I don’t care.

What follows is a rant laced with profanity. No apologies. Drag and drop deserves no better.

### Who got us into this mess?

Microsoft “designed” and implemented drag and drop way back in 1999, when IE 5.0 was released. IE versions has supported it ever since.

This specification was terribly bad, as we’ll see in a moment. Microsoft dropped the ball _majorly_ here.

Still, while Microsoft is to blame initially, the HTML5 WG and the other browser vendors are accessories to the crime.

One of the guiding principles of HTML5 and its WHAT-WG precursors is to document everything that already works in browsers but previous Working Groups couldn’t be arsed to specify, such as `innerHTML` and `offsetWidth`.

Although I thoroughly support that principle and see how it applies to the Microsoft drag and drop module, I still think that some form of critical reflection might have been in order in this particular case.

[Hixie said][3]:

> The drag-and-drop API is horrible, but it has one thing going for it: IE6 implements it, as do Safari and Firefox.

Now that is undeniably true. God knows why, but Firefox, Safari, and Chrome have shoveled it straight into their rendering engines, and critical reflection be damned. Only Opera has retained its sanity.

Interoperability is very important. But not at any price. The price is too high when it comes to drag and drop.

### The transcript of my testing sessions

OK, so what exactly is wrong with the HTML5 drag and drop module? 

I’ll show you.

Below follows an approximate transcript of my testing sessions. It shows you what I went through and why I wrote this entry.

This was an exceptionally bad case. The worst I’ve encountered since the demise of Netscape 4, in fact. That’s why the transcript includes profanity. Lots and lots of profanity.

#### Too many events

There are no less than seven events associated with drag and drop: dragstart, drag, dragover, dragenter, dragleave, drop, and dragend.

This seems rather a lot for a series of actions that can be accurately described by the mousedown, mousemove, and mouseup events.

In itself that’s not a disaster, just bad API design. We have to pick a few events and ignore the rest.

[ ... tinker ... ]

[ ... tinker ... ]

#### Say. Fucking. WHAT?!?

The drop event fires when the user drops an element he’s dragging.

And, you see, dropping the element you’re dragging is the POINT of this entire module.

So drop is the most important event. But it doesn’t fire. Let’s see ...

[ ... tinker ... ]

[ ... consult spec and example ... ]

OK, got it.

For the drop event to fire at all, you have to cancel the defaults of both the dragover and the dragenter event.

[ ... ]

... say WHAT?!?

OK, let’s try again:

The default action of the dragover and the dragenter events is _NOT_ being able to drop an element. And you have to cancel these default actions in order to drop an element. Obviously.

[ ... ]

Say. Fucking. WHAT?!?

OK, one more time:

[The dragover and dragenter events exist][4] for the sole reason of forcing web developers who want to perform a drop action to cancel their obscure default actions.

You’re kidding me.

[ ... crickets ... ]

You’ve GOT to be FUCKING kidding me!

I’m not going to cancel the default actions of not one but _two_ of your _bullshit_ events in order to get the most important action in the _entire fucking module_ working.

Then we won’t play. Nyaa, nyaa...

You bunch of fucking idiots don’t have the _fuckingest_ clue what you’re doing!

[ ... crickets ... ]

Now listen carefully, and you might actually learn something:

Default actions are supposed to be defined in positive terms: if you take _this_ action, _that_ will happen, unless the script cancels it. That’s how JavaScript events were designed to work.

[ ... crickets ... ]

No wonder I can’t give up smoking.

[ ... drag ... ]

Calm down, calm down. Let it be. Maybe it’ll go away by itself.

Do something else first.

#### Return to normalcy

When I defined a dragstart event handler, the other events just stopped firing in IE. All of them.

When I studied [Remy Sharp’s test case][5], however, I found it works in IE8 despite the presence of the dragstart event.

This is a strange inconsistency, especially since the spec is supposed to be _based_ on the IE implementation. So either the spec has overlooked a special case in which all the other events are canceled, or IE sometimes doesn’t implement its own implementation.

I’m guessing the latter right now. Browser bug #1. To be retested, ascertained, and documented.

Phew, finally something _normal_.

Maybe the ... other thing ... will turn out not so bad, after all.

But first some more events.

#### dragthis

The drag event is like mousemove, except that it fires during a drag operation. Hey, this makes sense! Works everywhere? Yup. Next.

#### dragthat and dragsomethingelse

In theory dragenter and dragleave could be great events, since they fire when you enter or leave an HTML element in the middle of a drag operation. If that element is a valid drop target you could change its styles ondragenter and ondragleave to indicate this fact to the user.

With the spec being based on the Microsoft API, I expected dragenter and dragleave to emulate mouseenter and mouseleave. But they didn’t. Not even in IE. They’re based on mouseover and mouseout and suck every bit as badly. And their names are wrong.

Mouseover and mouseout are terrible because they bubble up all the time and make it very hard to distinguish important events from unimportant ones. If I mouse over (or drag enter) a child element of the one that the event is set on, it also fires. And that’s exactly what we _don’t_ want. The events will fire incessantly the whole time the mouse is above the element, and we have to work hard in order to distinguish useful events from useless ones.

[Mouseenter and mouseleave][6], on the other hand, fire only when you enter and leave the element they’re defined on, and they don’t bubble. That makes them much easier to use.

They are Microsoft extensions, by the way, and excellent ones at that. They work only in IE.

Note that originally mouseenter and mouseleave had _exactly the same_ IE only compatibility pattern as drag and drop. Mouseenter and mouseleave are a good idea, drag and drop ... isn’t. Guess what the other browsers chose to implement?

No wonder web development is such a fucking pain with fucking morons in charge of the browsers.

Wait, that could be construed as an insult to morons.

Ah, what the fuck.

#### dragbullshit

Dragover, now, has nothing to do with mouseover. It’s exactly the same as the drag event, except that you can set it on any element instead of just the document. Or something. Whatever.

Why do we need the dragover event if we already have the drag event?

[ ... fume ... ]

To cancel its default action!

If we didn’t have to cancel its default action the dragbullshit event would _have no fucking point!_

And we can’t have pointless events in our nice specification, now, can we?

So we give it a default action. A _very complicated_ default action.

That has to be canceled. Absolutely, _positively_ has to be canceled.

[ ... crickets ... ]

Anybody LISTENING to what I say?

[ ... drag ... ]

I deserve a fucking MEDAL for this. Above and beyond the call of fucking DUTY.

#### draggable

Then we have the `draggable` attribute that, when set to `true`, allows an element to be dragged. It only works in Firefox. Links and images are draggable by default.

Actually that’s a pretty good idea.

Wow, I can finally say something nice. But to whom?

I’m _assuming_ that `draggable` is an HTML5 addition because it doesn’t work in IE, and therefore I’m _assuming_ I can congratulate the HTML5 WG with having had a good idea.

You see, I can’t find the Microsoft documentation on drag and drop, so I can’t check whether `draggable` is supposed to be supported in IE.

In practice it isn’t, that’s for sure.

(If you know where to find the Microsoft documentation, don’t bother leaving a comment. Meanwhile I don’t care any more.)

#### Safari fuckup

Next problem.

In order to get drag and drop working in Safari, add this _to your CSS!_
    
    
    #tobedragged {
    	-khtml-user-drag: element;
    }
    

[ ... ]

**Q**: Hi, how do you want me to present this element to the user?  
**A**: It’s draggable.

[ ... ]

Fuck you, Safari team. Fuck. You.

Wait, let’s rephrase that. A gentle question might help more than a rant.

Dear Safari team, does “separation of presentation and behaviour” mean anything to you?

[ ... crickets ... ]

Thought not.

[ ... drag ... ]

Fuck you anyway.

#### Drop effects? Or drag effects?

The [`dropEffect` property][7] might actually set the _drag_ effect. At least, that’s how I read the spec right now.

I could be wrong here. I have no fucking clue what a drag (or drop) effect is, and you don’t, either.

As an experiment I set the property to every single value the spec allows, and it made no difference whatsoever in any browser.

Then I discovered I had to set `effectsAllowed` to `all` in order to decree that all drop effects (which really may be drag effects) are allowed. This made no difference, either — no browser reacted to my setting of `dropEffect` by showing any of the now-allowed drag (or drop?) effects.

Some browsers report the value of `effectsAllowed` as `copyLink`, by the way. Just after I set it to `all` . A little creativity to show their good spirits, I presume.

And why would I need to give permission at all? Setting `dropEffect` to the desired value indicates that I command (and, by implication, permit) the effect to take place.

Doesn’t it?

[ ... crickets ... ]

[ ... crickets ... ]

Oh, fuck you. I give up.

### Strike

If you’re still not convinced that drag and drop sucks, read [Francisco Tolmasky’s article][8] on bugs and problems he encountered.

In fact, from his piece it almost seems as if the browser vendors have _trouble_ implementing drag and drop.

Gee, I wonder why that is.

But I’m not going to figure it out. I’ve had enough.

Any unanswered questions you might have after reading this piece will remain unanswered for all eternity, as far as I’m concerned. I don’t see why I should spend another two to three (unpaid) days on this pile of junk.

Go do your own research for a change.

And don’t bother leaving pointers to useful articles and stuff. I just don’t care any more, and I’m _certainly_ not going to read them.

I’m on strike.

* Written on 21 September 2009
* Categorized in [HTML5][9]
* Previous entry: [Fronteers 2009: many speakers, no tickets][10]
* Next entry: [Google Chrome Frame — technical notes][11]

This is the blog of [Peter-Paul Koch][12], web developer, consultant, and trainer. You can also follow him on [Twitter][13] or [Mastodon][14].  
[Atom][15] [RSS][16]

Categories:

* [Homepage][17]
* [Archives][18] (1)
* [Browsers][19] (8)
* [Chromia on Android][20] (12)
* [Coding techniques][21] (24)
* [Conferences][22] (104)
* [Content][23] (71)
* [Linkbait][24] (36)
* [Market share][25] (62)
* [Mobile][26] (30)
* [Personal][27] (28)
* [position fixed][28] (4)
* [rafp][29] (1)
* [The Mobile Web Handbook][30] (3)
* [Touch events][31] (14)
* [TV][32] (2)
* [Viewports][33] (37)
* [Web thinking][34] (16)

Monthlies:

* [January 2018][35] (3)
* [December 2017][36] (3)
* [November 2017][37] (1)
* [October 2017][38] (3)
* [September 2017][39] (1)
* [August 2017][40] (1)
* [July 2017][41] (2)
* [June 2017][42] (2)
* [May 2017][43] (1)
* [February 2017][44] (2)
* [January 2017][45] (1)
* [November 2016][46] (2)
* [October 2016][47] (3)
* [September 2016][48] (1)
* [July 2016][49] (5)
* [May 2016][50] (1)
* [April 2016][51] (4)
* [March 2016][52] (4)
* [February 2016][53] (4)
* [January 2016][54] (1)
* [December 2015][55] (3)
* [November 2015][56] (1)
* [September 2015][57] (3)
* [August 2015][58] (1)

### Comments

Comments are closed.

1 Posted by [Ian Hickson][59] on 21 September 2009 | [Permalink][60]

Yeah, I made up "draggable" because it seems there's no way to drag _elements_ in IE, only selections. Glad you like it. :-)

I wrote a blog post myself while reverse engineering this... interesting... API that Microsoft invented:

[http://ln.hixie.ch/?start=1115899732&count;=1][61]

I added an intro to the HTML5 spec recently, btw, which might help with introducing authors to this API so that they don't feel quite as bad as you do. :-)

2 Posted by ppk on 21 September 2009 | [Permalink][62]

Thanks, I hadn't found that article.

Sorry for the rant; hope you don't take it personally, but I feel that drag and drop should be rewritten from the ground up.

In fact I have some ideas about that. I want to think about it a bit more, and then publish them.

3 Posted by Tom on 21 September 2009 | [Permalink][63]

After reading this, I need a fucking heart surgeon!

4 Posted by Liam the lemming on 21 September 2009 | [Permalink][64]

This isn't a disaster. It's a goddamn *horror story*.

As with all the testing that's gone before it: Thank you, PPK, for suffering this unspeakable torment so we don't have to - and, now, know better than to try.

5 Posted by Robbert Broersma on 21 September 2009 | [Permalink][65]

Dismissing the dragenter/dragleave events in favour of mousedown/mouseup is quite contradictory to your rant in the mouse events compatibility table on browser vendors not implementing mouseenter/mouseleave.

Also, I think when it comes to browsers, there can never be too much specific events available (as long as they all implement one specification).

6 Posted by Bartek on 21 September 2009 | [Permalink][66]

About the weird cancel-default-action thing... There may actually be some logical reasons to it.

Isn't it the case that, by default, no elements should accept dropping a dragged element on them? I think that it's a reasonable action to reject any dragged element by default. If it was the other way around, *ANY* element on the page would accept dragged elements: you could drop them anywhere, because the default action would be to accept them (allow drop).

You don't want to tell every single element on the page (beside one or two) that it shouldn't accept dragged elements (because only the one or two elements are the valid drop areas).

So, by default, an element doesn't accept dropping.

Adding an event listener (e.g. dragenter) alone shouldn't change the behaviour of the element. It shouldn't change (or prevent) the default action. So you must prevent it manually, in the listener. 

7 Posted by [Francisco Tolmasky][67] on 21 September 2009 | [Permalink][68]

The worst part is that after much investigation, it appears that this API is more or less useless for tomorrow's breed of applications, which theoretically was the whole point of HTML 5.

Take Bespin for example. Since Bespin is rendered entirely into one canvas element, its prohibitively difficult (or actually impossible), to start a drag and drop. This is because the API is completely declarative, requiring you to mark entire elements as draggable or not. So you can't for example say "if you drag upwards, then drag and drop", because by the time you've figured this out its to late to cancel (or not cancel?) the event.

The prevent default thing is also a mess, because it prevents all defaults from happening. You wind up in situations where you want to cancel drags but not text selection, but are only given the option to do both. Quite frustrating.

I wouldn't expect much to be done about this however, I made a very conservative request to whatwg already and was basically told to wait until HTML 6.

8 Posted by ppk on 21 September 2009 | [Permalink][69]

Good point about the text selection; I hadn't thought of that yet.

Are you going to write a bit more about how drag and drop doesn't give us what we need? You seem to have done more research than I have.

9 Posted by kl on 21 September 2009 | [Permalink][70]

it's useless for 280slides and API is crap. So it's neither nice nor powerful. 

This API needs to be dropped, dragged behind a shed and shot in the head. 

10 Posted by [Derek Martin][71] on 21 September 2009 | [Permalink][72]

Ok, that's it. Maybe it *is* finally time for me to get out of web development, and try something sane, like direct-mail marketing :P

11 Posted by Ricardo on 21 September 2009 | [Permalink][73]

HTML6? The one which will be fully implemented by 2037?

12 Posted by Anonymous Someone on 21 September 2009 | [Permalink][74]

The issues I always came across was that it that the APIs were roughly line up with how the clipboard works. This is not a bad thing, it generally makes it easy for components to accept drop operations in a similar fashion to accepting a paste.

However security considerations have largely neutered setting the clipboard in the browser, setting the content of drag operation is unlikely to fare any better.

In the browser drag operations should be event rich, but work more like existing browser events. They should just drag node references around.

Dragging out of a browser will probably end up working just like the clipboard does. (ie out of the script writers control) Dragging into the browser could probably work a little like the proposed file api.  

13 Posted by Thomas Broyer on 21 September 2009 | [Permalink][75]

You're harsh!

Let's try to "explain" some points:

1\. dnd as specified in HTML5 and (more or less) implemented in IE, WebKit and Firefox 3.5, allows much more than what you can hack with mouse events; things that are not possible at all with an "old-school script", and *that's* the whole point of it: allowing dragging something (under your control!) to another application and/or receiving something from another application. Those things can be URLs, plain text, HTML, images, files, etc.

2\. You've asked for a Microsoft specification? Well, you know they don't do that, but they have some documentation nevertheless <http://msdn.microsoft.com/en-us/library/ms537658(VS.85).aspx>

3\. those 7 events are to be split into two groups: the ones firing at the *source* (the thing being dragged; namely: dragstart, drag and dragend, Microsoft also lists dragenter there but doesn't describe its role in this case) and the ones firing at potential *targets* (dragenter, dragover, dragleave and drop). You complained dragover was just like drag, well it fires at the same time, but on different objects.

[...to be continued...]

14 Posted by Thomas Broyer on 21 September 2009 | [Permalink][76]

[...continued...]

  
4\. the drop event: for the drop event to fire, you must have previously told the browser that this (the "current" element) is a valid drop target; and this must be done as soon as your mouse pointer enters the element (dragenter). Because the default behavior is to *not* be a drop target, cancelling the event actually makes the event target a drop target. As for the dragover event, I admit it's a bit "strange"; but it allows you to change the dropEffect depending on where the mouse is within the drop target (some kind of "image map" for DnD).

5\. As you said, -khtml-user-drag (or -webkit-user-drag) is a shame (it's noting to do with presentation, so shouldn't be CSS); well, draggable is the equivalent, just better.

6\. Finally, dropEffects vs. effectsAllowed; again, it's all about drag source vs. drop target: the source object sets the effectsAllowed (if it's read-only, it won't allow "move"; if it's inherently temporary, it won't allow "link", etc.) and the drop target choose a dropEffect among them.

Ah, and the introduction added by Ian makes all this much clearer overall if you ask me.

15 Posted by [Michael Wales][77] on 21 September 2009 | [Permalink][78]

I have one major problem with drag-drop in HTML5, just based on looking at the spec (I haven't attempted to use it, this reply will explain why).

HTML/xHTML is content - it's there to provide the content to the user in a semantic and readable fashion. It's not there to make it look pretty - it's not there to make it do fancy things, it's only job is to provide content.

Drag-and-drop is dynamic functionality. It has nothing to do with the content itself - it is 100% based in the users interaction with that content, which is outside the scope of HTML/xHTML.

HTML5 has disappointed me through-and-through. It's a half-hazardly thrown together spec that is only seeing adoption at this point in time because it has been in the works for so long. It is nowhere near ready and personally, I don't see any need for it.

I've tried to write documents to the HTML5 spec - it makes my job twice as hard, the code is harder to read (since HTML5 semantic elements don't really "do" anything) you still have to sprinkle divs/lis in to do anything functional. Just a waste of lines and deeper indentation throughout the document.

I'm sticking the xHTML 1.0 Strict - it's served me fine and HTML5 provides absolutely no benefit as a developer.

16 Posted by Connie Swail on 21 September 2009 | [Permalink][79]

You wrote: "There are no less than seven events associated with drag and drop: dragstart, drag, dragover, dragenter, dragleave, drop, and dragend."

There is an eighth event: dragnet.  
It's available at your local video store, or (illegally) through a BitTorrent.

My advise, forget about it all for a while and watch a movie from the pre-WWW era.

17 Posted by Nabil Elisa on 21 September 2009 | [Permalink][80]

i'd had similar experiences with drag and drop in the past but figured that i was simply too dumb to understand it. glad to see that i'm not alone!

i appreciate all the hard work that hixie (and co) has to do in keeping an evolving spec under control, but i definitely believe that this particular api should be rewritten from scratch with sanity in mind. franciscos post had some great ideas in it, and i suspect you too have a few of your own. please post them publicly and maybe we can get more people supporting them...

18 Posted by [Karl Adam][81] on 21 September 2009 | [Permalink][82]

I think since this is quirksblog I should point out these comments do not render properly on mobile safari and if they go over a certain length are simply clipped.

19 Posted by Chris on 21 September 2009 | [Permalink][83]

The spec may be a disaster, but your rant is absolutely brilliant :-)

20 Posted by Alejandro Moreno on 21 September 2009 | [Permalink][84]

@Thomas Broyer:

I think you missed the point. I'm sure persistent people can figure out how to work with the API and do fabulous things with it, but I feel PPK is fundamentally opposed to its abysmal design in the midst of the mostly reasonable and logical spec that HTML5 is.

21 Posted by [l.m.orchard][85] on 21 September 2009 | [Permalink][86]

I have to second Thomas Broyer on the reason for the 7 events, which you seem to have missed in the rant: 

Half of them fire on the thing dragged, while the others fire on the thing underneath potentially receiving the drop.

That's something you just can't do with "old school scripts" without resorting to homemade collision detection on coordinates. And forget about using event delegation on a list parent to easily detect a drag/drop on one of a hundred or so list elements.

And not only that, but the events on the drop targets can receive drags from outside the browser, which is a complete non-starter in old school scripts.

So, rant away, but please remember there's at least one baby in the olympic-sized pool of bathwater

22 Posted by [Ross Boucher][87] on 21 September 2009 | [Permalink][88]

@karladam They render correctly. It's just that the lack of a scroll bar on iPhone doesn't let you know that the comment is scrollable. 

And because of the way scrolling behaves in MobileSafari, it triggers two finger scrolling mode. Give that a shot on long comments and you will see.

23 Posted by Darkimmortal on 21 September 2009 | [Permalink][89]

I think you're wrong. The spec seems logical coming from a WinForms background, not from old drag+drop APIs in browsers.

24 Posted by [ohnoes][90] on 21 September 2009 | [Permalink][91]

The dnd APIs are verbose, yes. You want APIs to be verbose (within reason) - the opposite is much much much worse.

At first glance, the 'return false' approach does seem odd, but it makes a lot of sense..

As with most object-oriented APIs (on mac and windows) you can override the default behavior/handler. If you return false, you basically say 'well, I'm not going to handle this event; OS, you do it'

You might not know this design as a web developer, but millions of actual developers understand it. 

25 Posted by Ms2ger on 21 September 2009 | [Permalink][92]

@Alejandro Moreno: "the mostly reasonable and logical spec that HTML5 is"—seriously? Even the HTML5 spec itself doesn't agree with you. I quote: "It must be admitted that many aspects of HTML appear at first glance to be nonsensical and inconsistent."

26 Posted by Darkimmortal on 21 September 2009 | [Permalink][93]

@ohnoes

+1, OP is obviously not a developer.

27 Posted by xavier on 21 September 2009 | [Permalink][94]

Gosh, some technical analysis actually making sense. Someone is putting soul, and curse words, in the spec. May he be blessed.

The only logical alternative being to wait until everyone forgets it and keep implementing it as today using js, or that your favourite js library has spent enough time to hide the mess and present it into a digestible api that allows you to forget about how smelly it it below.

28 Posted by [Michael Butler][95] on 21 September 2009 | [Permalink][96]

I hope they work out a proper implementation of drag N drop, because it would be HUGELY beneficial (to users) with photo/video sharing on the web, allowing us to seamlessly copy files from our desktops to the web without having to go through annoying dialogs and clicking.

29 Posted by [Karl Adam][97] on 22 September 2009 | [Permalink][98]

@boucher You're right, but that may be the most undiscoverable interaction I've ever seen both due to the lack of scrollbar and the before never used two finger scroll gesture in Safari for an inner scrollview. Might be better to just show the full comment on Mobile Safari. Thanks for the tip though, next time I'll be able to read the comments without running back to desktop.

P.S. It's still a weird interaction on the desktop

30 Posted by [Sander Aarts][99] on 22 September 2009 | [Permalink][100]

ohnoes: "You might not know this design as a *web* developer, but millions of *actual* developers understand it." [emphasis mine]

Oh dear, here we go again.

31 Posted by [Erik Arvidsson][101] on 22 September 2009 | [Permalink][102]

WebKit has draggable as well if you got build 532.0 or newer:

https://bugs.webkit.org/show_bug.cgi?id=26262

32 Posted by [F1LT3R][103] on 22 September 2009 | [Permalink][104]

YOU SAID: "Default actions are supposed to be defined in positive terms: if you take this action, that will happen, unless the script cancels it. That's how JavaScript events were designed to work."

I SAY: "Huge industrial sledgehammer hitting the unmissably large nail on it's over-sized head. Over and over."

Thank you.

33 Posted by [Ryan McGrath][105] on 22 September 2009 | [Permalink][106]

How on earth did the spec ever get this far while being this cluttered? 

I'd also really like to know why anybody ever considered it a "plus" (in any sense) that a new spec "works" in IE6. At the risk of playing the same old broken record, that browser needs to die, and it shouldn't matter if newer specs are supported in older versions of IE.

34 Posted by geeves on 22 September 2009 | [Permalink][107]

I've been waiting for this breaking point for years. you do good and very valuable work for the web community here and I've long wondered why you've never called MS, Mozilla or Safari out on their glacier-like or haphazard development of "components" for "standards". (Yes, I'm lumping all 3 together, and I know it's not entirely their individual faults, if you have one moving forward without the others you have the next div vs layer argument amongst browsers.)

But this seems ridiculous, almost as bad as OS X not focusing on dropdowns.  

35 Posted by [Doug Schepers][108] on 22 September 2009 | [Permalink][109]

FWIW, we've added mouseenter and mouseleave to the DOM3 Events spec, and we have general commitment from the browser vendors to implement it. Check it out in the latest editor's draft:

<http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#event-type-mouseenter>

(Oh, and this will be completed and implemented more than a decade before 2022... )

36 Posted by [Jacob Rossi][110] on 22 September 2009 | [Permalink][111]

I agree, dragenter and dragleave should be closer to mouseenter and mouseleave (since they are more like CSS :hover). @Schepers: thanks again for adding mouseenter/mouseleave.

Moreover, why does HTML5 say copy/paste should be treated as a form of drag/drop (and thus fire drag/drop related events)?

If copy/paste fires drag/drop events then many sites may have unnecessary UI flicker because they have engineered some drag/drop state UI.

I complained about this to the webapps WG and the only real counterpoint I received was that treating copy/paste like drag/drop enables mobile users (without mouse) to trigger drag/drop.

See my thread here:  
<http://lists.w3.org/Archives/Public/www-dom/2009JulSep/0109.html>

Hixie replied later on, saying that he could add a flag indicating if it's a pragmatic drag or an interactive one. But I haven't seen that added (correct me if I'm wrong). 

I think it makes sense for drag/drop events themselves to be the indication of an interactive data transfer. To the user and the web author, copy/paste and drag/drop are 2 different things. This is the way it's currently implemented in most browsers' event models. Why muddle it?

37 Posted by [Brad Neuberg][112] on 22 September 2009 | [Permalink][113]

I'm confused... are you saying HTML 5 drag and drop sucks? Just kidding, I'm being a smart ass. I actually hadn't cracked this part of the HTML 5 spec open myself; disappointing to see that it's a pile of turd. Sometimes worse is better, except when it's worse.

38 Posted by [Mickael][114] on 22 September 2009 | [Permalink][115]

Hello y'all. I implemented HTML5 dnd, and I agree it's not easy to understand at first sight. But once you got it, I find it very powerfull. Drop events bubble : that's welcome because you can use the well-known "event delegation" technique ( <http://decafbad.com/blog/2009/07/15/html5-drag-and-drop> ). 

39 Posted by [Jonny Axelsson][116] on 22 September 2009 | [Permalink][117]

HTML5 drag&drop; has a potentially huge benefit over scripted drag&drop; in usability and accessibility. 

Scripted drag&drop; generally doesn't work at all if the user has no access to a mouse. A good number of devices don't have a mouse attached, phones, TVs, the Nintendo Wii... Drag&drop; also requires considerable coordination on behalf of the user. For most of us drag&drop; is liberating, but I too have spent time cursing over a badly designed drag&drop; application.

Of course a such API should be so convenient and efficient to use that it is preferable to hacking it out with a script.

<http://dev.opera.com/articles/view/accessible-drag-and-drop/>   
<http://my.opera.com/jax/blog/2009/07/09/keyboard-drag-and-drop-html-and-accessibility>   
<http://html5doctor.com/accessibility-native-drag-and-drop/>

40 Posted by [Speednet][118] on 22 September 2009 | [Permalink][119]

OMG, I have to bite my lip or something to stop the uncontrollable laughter. By the time I got to the Safari section I lost it.

I guess part of my reaction is that I recently shared a sliver of your experience, when I had to add drag-and-drop to my jQuery Watermark plugin (<http://jquery-watermark.googlecode.com/).> All I had to do was hide the watermark when something is dragged over a text element, and that took days to get to a point that sort-of works well.

I am constantly amazed that the HTML5 team does not fix stuff like this for good. As it stands, the official spec probably won't leave draft status for another 15 years, so it's not like there are many chances to fix bad specs.

41 Posted by [Christophe Eblé][120] on 22 September 2009 | [Permalink][121]

We've also implemented a native D&D; abstraction layer on top of IE, FF and WEBKIT and yes, that was really a BIG pain in the a**

On the other hand, this effort  
has given us a wealth of possibilities, impossible to achieve with simulated DnD.

42 Posted by [Mark McDonnell][122] on 22 September 2009 | [Permalink][123]

Thank you so much for the line...

"Fuck you, Safari team. Fuck. You."

...that had me in stitches :)

43 Posted by [Sebastian Markbåge][124] on 23 September 2009 | [Permalink][125]

ppk, you're lucky you gave up so quickly.

I've been trying to implement a these APIs - including backwards compatibility.

The APIs actually does have SOME merit when you get down to the cross-window operations. It enforces the source and the target to be completely unaware of each other. That makes it much easier to build new sources and targets.

That being said, the actual implementations are horrible. It's quite an overstatement that they work in all browsers.

There is a whole bunch of Windows specific bugs in WebKit. Some dropEffect combinations doesn't work at all in different UAs. The WebKit events are fired in the wrong order. Mozilla blocks mouse position in the drag event. setDragImage has a bunch of browser specific quirks, if it works at all. Browsers handle mime types in the OS differently. IE only accepts text/uri. Mozilla has custom mime types for OS drag and drops... and much more.

The most annoying of all... IE blocks the thread during drag operations, so you can't have setTimeout... i.e. no animations during drag!

44 Posted by [David Semeria][126] on 23 September 2009 | [Permalink][127]

I've been saying for a while that the whole D+D implmentation would be unnecessary if were simply possible to make elements transparent to certain events.

For example, if you make the item you're currently dragging transparent to the mouseover event, then when you drag it over a target element, that element's mouseover event will fire.

That's all you really need to do drag+drop - ie. know over which element the item was dropped. 

45 Posted by zm on 23 September 2009 | [Permalink][128]

There are only two lines in this post which have a substratum of truth in it:  
"Fuck you, Safari team. Fuck. You." and "Fuck you anyway." :)  
Otherway I think you can't understand a lot about the HTML5 dnd spec. I don't think it's the best as possible and easy to use. But it's not pointless.

46 Posted by [Sebastian Markbåge][124] on 23 September 2009 | [Permalink][129]

David, you can do this exact thing by using elementFromPoint (taking Opera quirk into account) while temporarily hiding the element. Described in this thread:

<http://groups.google.se/group/mootools-users/browse_thread/thread/f89432a1c151a981>

This is exactly what I'm doing for my coming MooTools implementation of the DnD APIs.

However, the point of the DnD APIs are not the mouse gestures per say, but the transfer of data. You have security issues and source/target separation to consider. They should really be called Data Transfer APIs.

It's a very different scope from the Drag and Drop APIs implemented in existing JS frameworks.

47 Posted by [Antonio Salazar Cardozo][130] on 23 September 2009 | [Permalink][131]

And no, knowing the element the item was dropped on is NOT all you have to do for Drag and Drop. The DnD described in HTML5 is used not only for in-browser drag and drop but also for dropping OUTSIDE the browser, which is critical. These APIs are modeled after standard GUI DnD APIs. Look at the way Qt implements DnD, for example, and you will find many clear similarities.

48 Posted by Marcwolf on 24 September 2009 | [Permalink][132]

Hi PPK  
I have just brought your book (again) after my first copy was 'borrowed' permanently by another developer.. I despise his morals but appreciate his desire to code.  
I am sorry you had to go through the DnD debarkle and wanted to thank you for your perserverance, and inventive command of the english language.  
To quote "there but through the grace of God go I"   
And therefore I leave it to far far better programmers to venture in the treachous swamps that is DnD.  
It seems like the concept of DnD is akin to another moniker of the same name "Dungeons and Dragons" except instead of heroic deeds and smiting of demons one is writing code and depatching bugs (hmm.. if I could transpose the user interface of Dungeons and Dragons for my Debugging processes then that would be more entertaining)  
But again many thanks for pointing out why DnD (although a lovely concept for desktop applications) is fraught with danger when used in a browser environment.  
Yours Sincerely  
Marcwolf

49 Posted by Christopher Boomer on 24 September 2009 | [Permalink][133]

You finally snapped! How therapeutic was *that*? Thank you (as ever) for trying...

50 Posted by [Andrew M][134] on 25 September 2009 | [Permalink][135]

This made my night. I didn't have time to read this but had to after the first few sentences. Thanks.

51 Posted by [Johan][136] on 29 September 2009 | [Permalink][137]

You didn't happen to record yourself while testing this? I'd pay big money to see your facial expressions.

52 Posted by [Axel Berger][138] on 4 October 2009 | [Permalink][139]

Two cents:  
Users may drop anything anywhere at any time, so setting up a default ignoring this and not doing something totally undesirable seems sensible to me. It is similar to clicks being ignored by default and clickability having to be turned on explicitly.  
Second:  
I try to avoid dragging like the plague, myself. It can trigger dozens of totally different actions and you never know what they'll be, especially if you miss the target by a pixel or two. I totally disagree with Michael Butler #28. The tool to use is FTP and has been for ages. It is simple and easy to understand. All those GUIs put users into a magical mindset, where actions have to be followed by rote learning in mind-numbing detail and the slightest mistake may trigger all kinds of Zauberlehrling effects. Compare that to the C64 era, when programming and using was perceived as something everyone could do, learn and understand.

53 Posted by Mark Kawakami on 8 October 2009 | [Permalink][140]

Great analysis. However, I don't think -khtml-user-drag is actually about drag and drop per se. I think it's about controlling how and what the is displayed when the user drags content from the webpage to elsewhere using the OS' drag-and-drop capabilities (for instance, dragging some selected text into a text editor). I may be wrong about this, but based on some experimenting I did earlier, that was the impression I got.

54 Posted by [Cables][141] on 13 October 2009 | [Permalink][142]

If only it were that easy. As it turns out, default behavior is sometimes to drag (as when you have already selected text). In my experiments this business of preventing default became quite frustrating, as sometimes you want to stop drags but not selection, or vice versa, but end up stopping both.

The correct way to do this is to allow the programmer to start a drag. As it stands, it is impossible to do things such as only allow vertical drags and not horizontal drags since the API is completely declarative and takes place on an element-by-element basis.

55 Posted by [Stephen][143] on 4 November 2009 | [Permalink][144]

Imo, the bubbling behavior of drag events isn't a bad thing, it enables other scenarios, you can replicate mouseenter/out events by scanning the relatedTarget, the failing with drag events is relatedTarget is NULL, the spec just says 'it should be null', not why it should be null. er, lovely..

56 Posted by Frank on 13 November 2009 | [Permalink][145]

this must have been one of the funniest articles regarding a mundane topic .. i have read ... uhmm: EVER! awesomest! thx 4 that!

[1]: http://dev.w3.org/html5/spec/editing.html#dnd
[2]: http://www.quirksmode.org/js/dragdrop.html
[3]: http://twitter.com/Hixie/status/4075253361
[4]: http://dev.w3.org/html5/spec/editing.html#events-fired-during-a-drag-and-drop-action
[5]: http://html5demos.com/drag
[6]: http://www.quirksmode.org/dom/events/mouseover.html
[7]: http://dev.w3.org/html5/spec/editing.html#dom-datatransfer-dropeffect
[8]: http://www.alertdebugging.com/2009/08/16/on-html-5-drag-and-drop/
[9]: http://www.quirksmode.org/blog/archives/archives/theory/html5/index.html
[10]: http://www.quirksmode.org/blog/archives/2009/09/fronteers_2009_3.html
[11]: http://www.quirksmode.org/blog/archives/2009/09/google_chrome_f.html
[12]: http://www.quirksmode.org/about/
[13]: http://twitter.com/ppk
[14]: https://mastodon.social/@ppk
[15]: http://www.quirksmode.org/blog/atom.xml
[16]: http://www.quirksmode.org/blog/index.xml
[17]: http://www.quirksmode.org/blog/
[18]: http://www.quirksmode.org/blog/archives/archives/index.html ""
[19]: http://www.quirksmode.org/blog/archives/browsers/index.html "Browser news"
[20]: http://www.quirksmode.org/blog/archives/chromia_on_android/index.html ""
[21]: http://www.quirksmode.org/blog/archives/coding_techniques/index.html "Notes about HTML, CSS or JavaScript coding techniques"
[22]: http://www.quirksmode.org/blog/archives/conferences/index.html "Conferences I attended"
[23]: http://www.quirksmode.org/blog/archives/content/index.html "New or updated pages on QuirksMode.org"
[24]: http://www.quirksmode.org/blog/archives/linkbait/index.html "What's going on elsewhere"
[25]: http://www.quirksmode.org/blog/archives/market_share/index.html ""
[26]: http://www.quirksmode.org/blog/archives/mobile/index.html "The mobile world"
[27]: http://www.quirksmode.org/blog/archives/personal/index.html "About my life"
[28]: http://www.quirksmode.org/blog/archives/position_fixed/index.html ""
[29]: http://www.quirksmode.org/blog/archives/rafp/index.html ""
[30]: http://www.quirksmode.org/blog/archives/the_mobile_web_handbook/index.html ""
[31]: http://www.quirksmode.org/blog/archives/touch_events/index.html ""
[32]: http://www.quirksmode.org/blog/archives/tv/index.html ""
[33]: http://www.quirksmode.org/blog/archives/viewports/index.html ""
[34]: http://www.quirksmode.org/blog/archives/web_thinking/index.html "My thinking about the web"
[35]: http://www.quirksmode.org/blog/archives/2018/01/index.html
[36]: http://www.quirksmode.org/blog/archives/2017/12/index.html
[37]: http://www.quirksmode.org/blog/archives/2017/11/index.html
[38]: http://www.quirksmode.org/blog/archives/2017/10/index.html
[39]: http://www.quirksmode.org/blog/archives/2017/09/index.html
[40]: http://www.quirksmode.org/blog/archives/2017/08/index.html
[41]: http://www.quirksmode.org/blog/archives/2017/07/index.html
[42]: http://www.quirksmode.org/blog/archives/2017/06/index.html
[43]: http://www.quirksmode.org/blog/archives/2017/05/index.html
[44]: http://www.quirksmode.org/blog/archives/2017/02/index.html
[45]: http://www.quirksmode.org/blog/archives/2017/01/index.html
[46]: http://www.quirksmode.org/blog/archives/2016/11/index.html
[47]: http://www.quirksmode.org/blog/archives/2016/10/index.html
[48]: http://www.quirksmode.org/blog/archives/2016/09/index.html
[49]: http://www.quirksmode.org/blog/archives/2016/07/index.html
[50]: http://www.quirksmode.org/blog/archives/2016/05/index.html
[51]: http://www.quirksmode.org/blog/archives/2016/04/index.html
[52]: http://www.quirksmode.org/blog/archives/2016/03/index.html
[53]: http://www.quirksmode.org/blog/archives/2016/02/index.html
[54]: http://www.quirksmode.org/blog/archives/2016/01/index.html
[55]: http://www.quirksmode.org/blog/archives/2015/12/index.html
[56]: http://www.quirksmode.org/blog/archives/2015/11/index.html
[57]: http://www.quirksmode.org/blog/archives/2015/09/index.html
[58]: http://www.quirksmode.org/blog/archives/2015/08/index.html
[59]: http://ln.hixie.ch/ "http://ln.hixie.ch/"
[60]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12540
[61]: http://ln.hixie.ch/?start=1115899732&count=1
[62]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12541
[63]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12542
[64]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12543
[65]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12544
[66]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12545
[67]: http://alertdebugging.com "http://alertdebugging.com"
[68]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12546
[69]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12547
[70]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12548
[71]: http://geek.derekmartin.ca "http://geek.derekmartin.ca"
[72]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12549
[73]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12550
[74]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12551
[75]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12552
[76]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12553
[77]: http://www.michaelwales.com/ "http://www.michaelwales.com/"
[78]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12554
[79]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12555
[80]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12556
[81]: http://Http://matrixpointer.com/Karl "http://Http://matrixpointer.com/Karl"
[82]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12557
[83]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12558
[84]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12559
[85]: http://decafbad.com/ "http://decafbad.com/"
[86]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12560
[87]: http://280north.com "http://280north.com"
[88]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12561
[89]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12562
[90]: http://noes.com "http://noes.com"
[91]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12563
[92]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12564
[93]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12565
[94]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12567
[95]: http://www.rustybrick.com/blog "http://www.rustybrick.com/blog"
[96]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12568
[97]: http://matrixpointer.com/karl "http://matrixpointer.com/karl"
[98]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12569
[99]: http://jlix.net/ "http://jlix.net/"
[100]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12570
[101]: http://erik.eae.net/ "http://erik.eae.net/"
[102]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12571
[103]: http://hyper-metrix.com "http://hyper-metrix.com"
[104]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12572
[105]: http://twitter.com/ryanmcgrath "http://twitter.com/ryanmcgrath"
[106]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12573
[107]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12574
[108]: http://schepers.cc "http://schepers.cc"
[109]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12575
[110]: http://www.jacobrossi.com "http://www.jacobrossi.com"
[111]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12576
[112]: http://codinginparadise.org "http://codinginparadise.org"
[113]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12577
[114]: http://dready.byethost31.com/ "http://dready.byethost31.com/"
[115]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12578
[116]: http://my.opera.com/jax "http://my.opera.com/jax"
[117]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12580
[118]: http://www.speednet.biz/ "http://www.speednet.biz/"
[119]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12581
[120]: http://blog.justswell.org "http://blog.justswell.org"
[121]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12582
[122]: http://www.integralist.co.uk/ "http://www.integralist.co.uk/"
[123]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12583
[124]: http://blog.calyptus.eu/ "http://blog.calyptus.eu/"
[125]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12585
[126]: http://lmframework.com/blog/about "http://lmframework.com/blog/about"
[127]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12586
[128]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12587
[129]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12588
[130]: http://shadowfiend.posterous.com/ "http://shadowfiend.posterous.com/"
[131]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12589
[132]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12590
[133]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12591
[134]: http://www.visualremedies.com "http://www.visualremedies.com"
[135]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12593
[136]: http://johanbenjaminsson.com "http://johanbenjaminsson.com"
[137]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12605
[138]: http://berger-odenthal.de "http://berger-odenthal.de"
[139]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12626
[140]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12638
[141]: http://www.zoombits.co.uk/cables "http://www.zoombits.co.uk/cables"
[142]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12669
[143]: http://meandmycode.com "http://meandmycode.com"
[144]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12717
[145]: http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html#c12735

