drag and drop not working in IE - Javascript, HTML5

后端 未结 4 1733
自闭症患者
自闭症患者 2020-12-19 11:09

I\'ve built this checker-board app which uses HTML5\'s Drag&Drop with javascript. It works great on chrome and firefox, but not on IE9 or IE8. My guess is that the probl

4条回答
  •  感情败类
    2020-12-19 11:49

    You need to do two things for the drag and drop to work in I.E..

    1) When you set and get the data use 'text' and not 'text/html'

    e.dataTransfer.setData('text', this.innerHTML);
    
    e.dataTransfer.getData('text');
    

    2) Prevent the default behaviour when handling 'dragenter' (as well as 'dragover').

    function handleDragEnter(e) {
        if (e.preventDefault) { 
            e.preventDefault(); 
        } 
        ... 
    }
    

提交回复
热议问题