作家
登录

GWT中复制到剪贴板 js+flash实现复制 兼容性比较好

作者: 来源:www.28hudong.com 2013-03-30 01:48:23 阅读 我要评论

但是用flash就可以复制。例子就是VeryCd,看“复制选中的连接”按钮是一个flash。看来flash的安全沙箱没有限制将内容复制到剪贴板 但是也是有限制的: 1 根据ZeroClipborad的人们说,这些flash必须通过网络加载。 Zero Clipboard Does Not Work From Local Disk This is a security restriction by Adobe Flash Player. Unfortunately, since we are utilizing the JavaScript-to-Flash interface ("ExternalInterface") this only works while truly online (if the page URL starts with "http://" or "https://"). 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: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html 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)复制代码 代码如下:package zero.clipboard.test.client; import java.util.Date; import zero.clipboard.test.client.ZClipboardBinder.ClipboardListener; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.button.Button; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class Zeroclipboard_test implements EntryPoint { public void onModuleLoad() { LayoutContainer c = new LayoutContainer(); c.setSize(400, 300); Button btn = new Button("Copy Hello World"); // 将控件和ZeroClipboard绑定 // ZClipboardBinder.bind(btn, "Hello World"); ZClipboardBinder.bind(btn, new ClipboardListener() { @Override public String prepareCopy() { return (new Date()).toString(); } }); c.add(btn); RootPanel.get().add(c); } } 相关下载都在附件中了。 attachment.zip 示意结果 点击按钮后——其实是点击了上面的flash,使用ctrl+v,就能看到结果。 现在发现有很多有意义的功能都不能用javascript实现,例如多文件上传和复制到剪贴板,都是通过flash做中介,“曲线”实现的 ,不知道最后HTML5有没有解决这些问题,不用我们兜兜转转。Zero Clipboard 开源的 JavaScript+flash 复制库类

  推荐阅读

  用jQuery实现的模拟下拉框代码

很多群员问了关于下拉框美化的问题,现打一个下拉框美化的制作过程,其实是模拟出来的下拉框。 问题1:为什么要模拟下拉框? 1,浏览器自带的 下拉框样式不好看。 2,在ie6下,下拉框的优先级大于层,经常导致下拉>>>详细阅读


本文标题:GWT中复制到剪贴板 js+flash实现复制 兼容性比较好

地址:http://www.17bianji.com/kaifa2/JS/26923.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)