window.clipboardData 不是 Javascript 的一部分?
在我搜索以编程方式选择 WebView 内容的 Javascript 方法中,我遇到了这个Javascript代码片段,它使用了一种方法名为 setData() 的成员位于 window 对象中名为 ClipboardData 的成员中。
但是当我尝试在 Javascript 参考 中查找它的文档时,clipboardData 无处可去被发现。
为什么?
window.clipboardData 不是 Javascript 或 DOM 的一部分吗?
In my search for a Javascript way to programmatically select WebView content, I encountered this Javascript code snippet, which uses a method named setData() in a member named clipboardData in the window object.
But when I tried to find documentation for it in a Javascript reference, clipboardData was nowhere to be found.
Why?
Isn't window.clipboardData not part of Javascript or DOM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它不属于任何标准。除 IE 之外,出于安全考虑,大多数浏览器都不允许访问剪贴板(您不希望任意网页读取您放入剪贴板的敏感信息)。
No, it's not part of any standard. Except for IE, most browsers don't allow clipboard access because of security concerns (you don't want arbitrary webpages reading something sensitive information that you put into your clipboard).
我相信只有 IE 允许您访问剪贴板。其他浏览器的旧版本曾经使用过,但作为安全措施,它已默认关闭。用户可以通过设置/选项/首选项明确打开它,但这在大多数情况下显然并不理想。
解决方法是在页面上使用 Flash 对象。由于Flash 10 添加了更多安全层,因此现在还需要用户与Flash 对象进行交互(例如,单击而不是说onload 事件)。
我从答案底部写得好的文章中发现并实施了出色的工作。他更详细地解释了这个问题,并提供了 Adobe/Mozilla 官方声明的链接,并提供了一个可用和可下载的示例以及 fla 的源代码。如果您想重新设计/重新设计他的按钮,这会很方便。
我已经使用最新的(截至 2011 年 7 月 7 日)Chrome/Safari/RockMelt/FF/IE7/IE8/IE9 和 MacOSX(SL) Safari/FF 在 Windows7 上成功进行了测试。
唯一的缺点是它使用闪存,除了某些移动平台和一小部分(ab)普通用户之外,基本上都很好。另外我发现你需要通过http(网络服务器)访问,通过文件系统打开和使用演示页面(即在资源管理器中双击html文件)将不起作用。
感谢分享拉胡尔,干得很棒。
http:// /www.rahulsingla.com/blog/2010/03/cross-browser-approach-to-copy-content-to-clipboard-with-javascript
I believe only IE lets you access the clipboard. Older versions of other browsers used to, but this has been switched off by default as a security measure. Users can explicitly turn it on via settings/options/preferences, but this is obviously not ideal in most situations.
The workaround is to use a flash object on the page. Since Flash 10 added more security layers, user interaction is also required now with the flash object (e.g. a click rather than say onload event).
I found and implemented the good work from the well written article at the bottom of my answer. He explains the issue in more detail, with links to official statements from Adobe/Mozilla and supplies a usable and a downloadable example, and the source code to the fla. This is handy if you want to reskin/redesign his button.
I have tested successfully on Windows7 using latest (as at 7/7/2011) Chrome/Safari/RockMelt/FF/IE7/IE8/IE9 and MacOSX(SL) Safari/FF.
The only downside is that it uses flash which is mostly fine except for some mobile platforms and a small portion of (ab)normal users. Also I found you need to access over http (a web server), opening and using the demo page via the file system (i.e. double clicking the html file in Explorer) won't work.
Thanks for sharing Rahul, awesome job.
http://www.rahulsingla.com/blog/2010/03/cross-browser-approach-to-copy-content-to-clipboard-with-javascript