Firefox: dragstart event doesn’t fire in hyperlink

2019-05-20 04:11发布

问题:

There is a problem handling a draggable element which is a child of a hyperlink (a href). Here is HTML:

<a href="#" id="a">Some text
    <span id="span" draggable="true">and some more text</span>
</a>

I try to catch dragstart events for both elements in JS:

var a = document.getElementById('a');
a.addEventListener('dragstart', function() {
  console.log('Dragging a link…');
});

var span = document.getElementById('span');
span.addEventListener('dragstart', function() {
  console.log('Dragging a span…');
});

In Firefox (28.0, Windows 8 and Ubuntu 13.10), if I try to drag the span, only the first handler triggers, but never the second. Other browsers (Chrome, IE) call both handlers successfully. How to make Firefox behave the same way?

回答1:

This is bug 1177704.

Remove href from a for a workaround.