问题描述
我有这个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 browserIs 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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!