简体   繁体   English

HTML5拖放不能在IE11上运行

[英]HTML5 drag and drop not working on IE11

Got HTML5 native drag and drop applied, drop is no working with IE, working well with chrome and firefox. 得到了HTML5原生拖放功能,drop不适用于IE,与chrome和firefox配合得很好。

the dragging appears to be working but drop isnt happaning on IE. 拖动似乎工作,但下降不是在IE上。

another small question - in IE i got a half transparent square around my draggable element, but its background is transparent(the image is done like that), and on chrome/firefox i dont have that square and the image look without any background while dragging. 另一个小问题 - 在IE浏览器中,我的可拖动元素周围有一个半透明的正方形,但它的背景是透明的(图像是这样完成的),而在chrome / firefox上我没有那个正方形,拖动时图像看起来没有任何背景。

this is the drop area: 这是下降区域:

<div id="4x2" class="dropArea" draggable="false" ondragenter="drag_enter(event); return false;" ondrop="drag_drop(event); return false;" ondragover="return false" ondragleave="drag_leave(event); return false;" data-droppable="true" onmouseover="return mouseOver(this); return false;" onclick="return movePlayer(this); return false;" onmouseout="return mouseOut(this); return false;">
</div>

this is the draggable element: 这是可拖动的元素:

<div id="player1" draggable="true" ondragstart="drag_start(event); return false;" ondragend="drag_end(event); return false;" data-droppable="false" onclick="return selectPlayer(this); return false;" data-selectable="true"></div>
function drag_start(e) 
    {
        e.dataTransfer.effectallowed = 'copy';
        e.dataTransfer.dropEffect = 'copy';
        e.dataTransfer.setData("text/plain", e.target.getAttribute('id'));
    }

function drag_enter(e) {

        if (e.target.getAttribute('data-droppable') == 'true') {
            e.target.style.backgroundImage = "url(images/board_cell_background_highlight.png)";
        }

function drag_leave(e) {

        if (e.target.getAttribute('data-droppable') == 'true') {
            e.target.style.backgroundImage = "url(images/board_cell_background.png)";
        }


function drag_drop(e) {
        var element = e.dataTransfer.getData("Text"); // the player
        if (e.preventDefault) {
            e.preventDefault();
        }
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        if (e.target.getAttribute('id') == "player1" || e.target.getAttribute('id') == "player2") {
            alert("invalid Move");
            return false;
        }

        e.target.style.backgroundImage = "url(images/board_cell_background.png)";
        moveHandler(element, e.target.getAttribute('id'));
    }

function drag_end(e) {
        e.dataTransfer.effectallowed = 'copy';
        alert("drop end")
        }
    }
}

I remove some code of printing stuff to make the code more shorter. 我删除了一些打印代码,以使代码更短。

You are setting data of type text/plain , but retrieving data of type Text . 您正在设置text/plain类型的数据,但检索Text类型的数据。 While some browsers might understand them to be one and the same, others may not. 虽然有些浏览器可能会理解它们是同一个,但其他浏览器可能不会。 In this case, it seems Internet Explorer is being pedantic while Chrome and Firefox are being lax. 在这种情况下,似乎Internet Explorer正在迂腐,而Chrome和Firefox则不严格。

Personally, I'd suggest using Text . 就个人而言,我建议使用Text It might be old, but that's what would make it work fine, even as far back as IE5, if memory serves, given some small adjustments to the event handling. 这可能是旧的,但是如果内存服务的话,即使早在IE5上也可以使它工作正常,只要对事件处理进行一些小的调整。

如果有人在Internet选项安全性选项卡中没有在IE 8.1 W中拖放11并删除复选框保护模式或以管理员身份运行IE

IE10/11 uses Text as the data string and it breaks if you use text/plain. IE10 / 11使用Text作为数据字符串,如果使用text / plain则会中断。 If you use Text, it breaks in Firefox. 如果您使用文本,它会在Firefox中中断。

I get around this by doing something like this in whatever drag and drop functions I need to write: 我通过在我需要编写的任何拖放功能中执行类似的操作来解决这个问题:

var setDataString = 'text/html';
// We need to change the setDataString type for IE since IE doesn't support setData and getData correctly. 
this.changeDataStringForIe = (function() {
    var userAgent = window.navigator.userAgent,
    msie = userAgent.indexOf('MSIE '),       //Detect IE
    trident = userAgent.indexOf('Trident/'); //Detect IE 11

    if (msie > 0 || trident > 0) {
        setDataString = 'Text';
        return true;
    } else {
        return false;
     }
})();

I'd love to know of a solution that doesn't use userAgent sniffing. 我想知道一个不使用userAgent嗅探的解决方案。

问题是浏览器默认为平移操作而不是触摸操作...请参阅http://msdn.microsoft.com/en-us/library/ie/dn265022(v=vs.85).aspx以获取有关如何操作的信息控制css中的默认操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM