同时支持iexplorer和firefox的javascript复制拷贝信息到剪贴板方法
今天找了很久的代码,换了一个又一个,都不行,明明很多人说可行的,为什么到我这里就不行了呢。最后还是一个英文博客文章找到了一些说法。因为我不懂flash,最终的做法还没有,但是可以提供一些思路给同样迷惑的同学们。
复制到剪贴板在ie里面实现很简单很简单,仅需要用到函数window.clipboardData.setData("Text",varstring);
问题是如何在firefox下实现。目前网上有两种方法。
第一种,比较少见,利用firefox的特性,相关文章参考https://developer.mozilla.org/en/Using_the_Clipboard。用这种方法一般需要用户修改firefox的默认设置,非常麻烦。
第二种,利用flash,在Javaeye和Discuz!中都是用这种方法,据说05年就出现了。这种方法的关键是利用flash的复制功能
<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(s)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>
这里需要用到一个clipboard.swf文件,网上有很多现成的,可直接下载。
这就是我找到的两种方法,对比一下,第二种肯定是首选,而且应用也很广,可惜的是,我在网上找到的所有代码都不可用了。
原因在这篇文章的评论中提到了http://www.jeffothy.com/weblog/clipboard-copy/.更新Flash 10后,禁止用户在没有点击flash的情况下复制内容,原来的方法失效了。解决方法是在按钮的上面覆盖一层透明的复制用的flash(这是dz所采用的方法),或者直接使用一个用flash做的复制按钮(这个方法Javaeye在用)。
发表于2009-9-27 16:03
IЎЇm delighted that I have noticed this weblog. Lastly anything not a junk, which we undergo extremely frequently. The website is lovingly serviced and stored as much as date. So it need to be, thanks for sharing this with us.
Thanks for taking the time to discuss this, I really feel strongly about it and love studying more on this topic. If doable, as you gain expertise, would you thoughts updating your blog with additional data? It is extremely helpful for me.
Hi there clever points.. now why did not i consider these? Off topic slightly, is this web page sample merely from an odd installation or else do you employ a personalized template. I take advantage of a webpage i’m searching for to improve and nicely the visuals is probably going one of the key things to complete on my list.
<a href="http://blog.bitcomet.com/post/1448950/">Order Cheap Cymbalta</a>