window.clipboardData.getData("文本")在chrome中不起作用 [英] window.clipboardData.getData("Text") doesnt work in chrome

查看:3216
本文介绍了window.clipboardData.getData("文本")在chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个javascript函数:

pre $函数maxLengthPaste(field,maxChars)
{
event .returnValue = FALSE; ((field.value.length + window.clipboardData.getData(Text).length)> maxChars){
field.value = field.value + window.clipboardData.getData( Text)。substring(0,maxChars - field.value.length);
返回false;
}
event.returnValue = true;



$ b window.clipboardData.getData(Text )在Chrome浏览器中不起作用
是否有任何交叉浏览器代码替代它?

不,对 window.clipboardData 没有跨浏览器支持。它只支持IE。支持 window.clipboardData 通常被认为是一个安全问题,因为它允许您访问的每个网站读取当时剪贴板中发生的任何事情。



在Chrome中,您可以在处理粘贴事件时阅读 clipboardData

  document.addEventListener('paste',function(evt){
console.log(evt.clipboardData.getData('text / plain'));
});


I have this javascript function:

function maxLengthPaste(field,maxChars)
{
    event.returnValue=false;
    if((field.value.length + window.clipboardData.getData("Text").length) > maxChars) {
        field.value = field.value + window.clipboardData.getData("Text").substring(0, maxChars - field.value.length);
        return false;
    }
    event.returnValue=true;
}

The window.clipboardData.getData("Text") doesn't work in Chrome browser Is there any crossbrowser code to substitute it?

解决方案

No, there is no cross-browser support for window.clipboardData. It is only supported by IE. Support for window.clipboardData is generally considered a security issue because it allows every website you visit to read whatever happens to be in your clipboard at the time.

In Chrome, you can read clipboardData when handling paste events:

document.addEventListener('paste', function (evt) {
  console.log(evt.clipboardData.getData('text/plain'));
});

这篇关于window.clipboardData.getData("文本")在chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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