最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML drag and drop in IE9 - Stack Overflow

programmeradmin3浏览0评论

I tried drag and drop in HTML. It is working good in all browsers except IE9 (no need to work on lower than IE9). ondrop event is not triggered in IE9.

any help? here is my code.

jsFiddle

Thanks in advance.

I tried drag and drop in HTML. It is working good in all browsers except IE9 (no need to work on lower than IE9). ondrop event is not triggered in IE9.

any help? here is my code.

jsFiddle

Thanks in advance.

Share Improve this question edited Aug 6, 2012 at 14:30 epascarello 208k20 gold badges205 silver badges244 bronze badges asked Aug 6, 2012 at 13:38 SathyaSathya 5,3048 gold badges45 silver badges66 bronze badges 3
  • stackoverflow./questions/5500615/… – thecodejack Commented Aug 6, 2012 at 13:42
  • @CodeJack, i have seen it already. There is no accepted solution. And i tried to replace <div> with <a> as suggested there. still no use. – Sathya Commented Aug 6, 2012 at 14:01
  • caniuse./#search=drag See the notes for IE – Rob Commented Aug 21, 2012 at 16:29
Add a ment  | 

1 Answer 1

Reset to default 6

It'll work if you replace div with a tags. However there are a couple of other changes you ought to make, firstly make sure that the a tags aren't clickable links by returning false in the onclick event:

<a class="div123" href="#" draggable="true"
 ondragstart="handleDragStart(event)"
 ondrop="handleDrop(event)"
 ondragover="dragoveHandler(event)"
 onclick="return false;">
    HTML5 drag and drop
</a>

Secondly, IE9 doesn't accept parameters of text/plain in setData, use Text instead or add the data inside of a try...catch. Also, you should make sure the data you're adding is actually text:

e.dataTransfer.setData("Text", "" + $(e.target).index());

Finally your handleDrop function needs to preventDefault/return false because otherwise the default action for dropping a link (an a element`) is to navigate to the dropped URL:

function handleDrop(e) {
    alert($(e.target).index());
    if (e.preventDefault) {
        e.preventDefault(); // Necessary. Stops redirect.
    }
    return false;
}

Here is a jsFiddle of your code which will work in IE9.

发布评论

评论列表(0)

  1. 暂无评论