window.clipboardData.getData(“Text”) 在 IE8 中返回 0

发布于 2024-10-05 10:51:20 字数 466 浏览 0 评论 0原文

我正在尝试在文本区域上实现 maxlength。在 IE7 中,window.clipboardData.getData("Text") 返回复制的正确字符数。在 IE8 中,相同的调用返回 0。出了什么问题?

这是js

var someRule= {
  "textarea" : function(element) {
    element.onpaste = function() {
      var copied = window.clipboardData.getData("Text");
      alert('copied length = '+copied.length);
    }
  }
};

Behaviour.register(someRule);

alt text

I'm trying to implement maxlength on a textarea. In IE7, window.clipboardData.getData("Text") returns the correct number of characters copied. in IE8, the same call returns 0. What's wrong?

here is the js

var someRule= {
  "textarea" : function(element) {
    element.onpaste = function() {
      var copied = window.clipboardData.getData("Text");
      alert('copied length = '+copied.length);
    }
  }
};

Behaviour.register(someRule);

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只涨不跌 2024-10-12 10:51:20

IE8 中有一个安全设置:

要防止网站读取您的剪贴板,请执行以下步骤:

转至“工具”->“Internet 选项”。
单击“安全”选项卡。
单击“自定义级别”。
向下滚动到“设置”下的“脚本”部分。
将“允许通过脚本进行粘贴操作”设置为禁用或提示。
按确定按钮关闭对话框。

在您的情况下,此设置可能已被禁用。

There is a security setting in IE8:

To prevent a web site from reading your clipboard, take the following steps:

Go to Tools->Internet Options.
Click on the Security Tab.
Click on "Custom Level."
Scroll down to the Scripting section under Settings.
Set "Allow paste operations via script" to Disable or Prompt.
Press the OK buttons to close the dialog boxes.

In your case, this setting is probably disabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文