Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 窗口粘贴Ctrl+;V addEventListener不是在IE 11中启动,而是在Chrome中启动_Javascript_Typescript_Window_Clipboard_Addeventlistener - Fatal编程技术网

Javascript 窗口粘贴Ctrl+;V addEventListener不是在IE 11中启动,而是在Chrome中启动

Javascript 窗口粘贴Ctrl+;V addEventListener不是在IE 11中启动,而是在Chrome中启动,javascript,typescript,window,clipboard,addeventlistener,Javascript,Typescript,Window,Clipboard,Addeventlistener,这是我的代码,在chrome浏览器中可以完美运行 window.addEventListener("paste", pasteHandler); //chrome 当剪贴板上从未触发selectCtrl+V时,问题出现在IE11浏览器中 我试过了,但没有成功 if (window.addEventListener) { alert("firefox, chrome, etc"); window.addEventListener("

这是我的代码,在chrome浏览器中可以完美运行

window.addEventListener("paste", pasteHandler); //chrome
当剪贴板上从未触发select
Ctrl+V
时,问题出现在IE11浏览器中

我试过了,但没有成功

if (window.addEventListener) {
    alert("firefox, chrome, etc");
    window.addEventListener("paste", pasteHandler, false);
} else if (window.attachEvent) {
    alert("IE");
    window.attachEvent("paste", pasteHandler);
}   
为什么呢

下面是我的代码

var canvas = document.getElementById("cc");
var ctx = canvas.getContext("2d");

if (window.addEventListener) {
    alert("firefox, chrome, etc");
    window.addEventListener("paste", pasteHandler, false);
} else if (window.attachEvent) {
    alert("IE");
    window.attachEvent("paste", pasteHandler);
}   

function pasteHandler(e) {
    if (e.clipboardData == false) return false; //empty
    var items = e.clipboardData.items;
    if (items == undefined) return false;
    for (var i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") == -1) continue; //not image
        var blob = items[i].getAsFile();
        var URLObj = window.URL || window.webkitURL;
        var source = URLObj.createObjectURL(blob);
        paste_createImage(source);
    }
}
var canvas=document.getElementById(“cc”);
var ctx=canvas.getContext(“2d”);
if(window.addEventListener){
警报(“firefox、chrome等”);
addEventListener(“粘贴”,粘贴处理程序,false);
}else if(窗口附件){
警惕(“IE”);
window.attachEvent(“粘贴”,粘贴处理程序);
}   
函数处理程序(e){
如果(e.clipboardData==false)返回false;//为空
var items=e.clipboardData.items;
如果(items==未定义)返回false;
对于(变量i=0;i
编辑


这不起作用

@Andreas抱歉,编辑问题正在进行中,您认为在IE中为什么不调用事件处理程序?这是否回答了您的问题@ritaj关于IE为什么不在粘贴事件上开火的问题的建议链接?@Andreas不工作,因为未在剪贴板中添加CTRL+V