- 时间:2022-01-06 01:29 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:GWT中复制到剪贴板 js+flash实现复制 兼容性比较好
但是用flash就可以复制。例子就是VeryCd,看“复制选中的连接”按钮是一个flash。看来flash的安全沙箱没有限制将内容复制到剪贴板
[img]http://files.jb51.net/upload/2010-3/20100307123454629.JPG[/img]
但是也是有限制的:
1 根据ZeroClipborad的人们说,这些flash必须通过网络加载。
[url=http://www.cnblogs.com/anic/admin/EditPosts.aspx?opt=1]http://[/url]" or "[url=https:]https://[/url]"). It won't work running from a local file on disk.
However, there is a way for you to edit your local Flash Player security settings and allow this. Go to this website:
[url=http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html]http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html[/url]
And add the path to your local "ZeroClipboard.swf" file to the trusted files list, or try the "allow all" option.
2 flash虽然提供复制功能,但是前提是要通过用户的一次点击。意思就是不能在javascript中通过函数的方式setText就复制到剪贴板,而是调用了这个setText函数后,用户的鼠标在flash上有了一次点击,才可以。
This library is fully compatible with Flash Player 10, which requires that the clipboard copy operation be initiated by a user click event inside the Flash movie.
这里和使用flash上传文件的swfupload有同样的问题。
使用ZeroClipboard,可以将网页内容复制到剪贴板。但是ZeroClipboard没有GWT封装,我们项目是用GWT的,所以就学着swfupload的GWT封装,把ZeroClipboard也封装成GWT可以调用的形式。
1 先封装了一个zeroclipboard.jar
2 项目中使用的是GXT控件库,为了和控件紧密结合,写了一个ZClipboardBinder类,将两者结合起来
3 使用方法见下(Zeroclipboard_test.java)
[url=http://xiazai.jb51.net/201003/yuanma/attachment.rar]attachment.zip[/url]
示意结果
[img]http://files.jb51.net/upload/2010-3/20100307123454442.JPG[/img]
点击按钮后——其实是点击了上面的flash,使用ctrl+v,就能看到结果。
[img]http://files.jb51.net/upload/2010-3/20100307123454751.JPG[/img]
现在发现有很多有意义的功能都不能用javascript实现,例如多文件上传和复制到剪贴板,都是通过flash做中介,“曲线”实现的 ,不知道最后HTML5有没有解决这些问题,不用我们兜兜转转。
[url=http://www.1sucai.cn/jiaoben/24961.html]Zero Clipboard 开源的 JavaScript+flash 复制库类 [/url]