但是用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)
相關下載都在附件中了。
示意結果
點擊按鈕后――其實是點擊了上面的flash,使用ctrl+v,就能看到結果。
現在發現有很多有意義的功能都不能用javascript實現,例如多文件上傳和復制到剪貼板,都是通過flash做中介,“曲線”實現的 ,不知道最后HTML5有沒有解決這些問題,不用我們兜兜轉轉。
Zero Clipboard 開源的 JavaScript+flash 復制庫類
新聞熱點
疑難解答