Internet Explorer上的粘贴事件侦听器获取错误的参数 [英] Paste event listener on Internet Explorer getting wrong arguments

查看:115
本文介绍了Internet Explorer上的粘贴事件侦听器获取错误的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 contenteditable 的粘贴事件,以便在粘贴之前清除所有HTML标记。所有工作正常 Firefox Chrome 。但是当我在 IE11 中测试我的代码时,传递的事件对象不是 ClipboardEvent 但是 DragEvent

I'm handling the paste events for a contenteditable to clean all HTML markers before paste. All Works fine in Firefox and Chrome. But when I test my code in IE11, the event object passed is not a ClipboardEvent but a DragEvent.

我的代码有问题吗?
如果我将侦听器添加为下面的代码,我是否应该获取剪贴板事件。我为什么要拖?

Is there something wrong with my code? If I add the listener as the code bellow, should I get the clipboard event. Why I'm getting drag?

editable.addEventListener('paste', pasteHandler, false);

http: //jsfiddle.net/vepo/4t2ofv8n/

要测试上面的示例,我将从Chrome复制文本并粘贴到IE中。但是我从IE复制任何文本都会得到同样的错误。

To test the example above, I'm copy a text from Chrome and paste into IE. But I you copy any text from IE will get the same error.

推荐答案

编辑

$(document).ready(function(){
    var editable = document.getElementById('editable-div');
    var pasteHandler = function(e){
        if(e.clipboardData && e.clipboardData.getData) {
            var pastedText = "";
            if (window.clipboardData && window.clipboardData.getData) { // IE
                pastedText = window.clipboardData.getData('Text');
            } else if (e.clipboardData && e.clipboardData.getData) {
                pastedText = e.clipboardData.getData('text/plain');
            }

            alert(pastedText);
        }
        else{
            alert('Not paste object!');
        }
    };
    editable.addEventListener('paste', pasteHandler, false);
});

这里我处理IE版本和其他浏览器。

here I handle the IE Version and the other browsers as well.

JSFiddle

这篇关于Internet Explorer上的粘贴事件侦听器获取错误的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆