複製到剪下板 相容(IE/FF/Chrome/..)

來源:互聯網
上載者:User

最近做一個複製到剪下板的功能   在網上找了很多都不好用  

最後發現在了  這篇文章很不錯  簡潔好用   貼出來  希望能幫到更多人

原文地址:http://www.lsproc.com/wiki/snippets:copytoclipboard

此代碼修改自 discuz!, 簡易實現

<script>var clipboardswfdata;          var setcopy_gettext = function(){    clipboardswfdata = document.getElementById('data').value;    window.document.clipboardswf.SetVariable('str', clipboardswfdata);}          var floatwin = function(){    alert('copy success, ' + clipboardswfdata);}</script>

        <style type="text/css">body {font-size:12px;}.clipinner {position:relative;}.clipboardswf {position:absolute; left:0; top:0;}</style>        <input type="text" name="data" value="xxxxx11111" id ="data" /><div id="clipboard_content"><span class="clipinner" id="clipinner">點此複製到剪貼簿<embed name="clipboardswf" class="clipboardswf" id="clipboardswf" onmouseover="setcopy_gettext()" devicefont="false" src="./clipboard.swf" menu="false" allowscriptaccess="sameDomain" swliveconnect="true" wmode="transparent" type="application/x-shockwave-flash" height="20" width="100"></span></div>

實現稍微有些噁心, 用 onmouseover 事件往 flash 中傳遞資料 

另: 沒有對ie單獨處理, ie中推薦使用 window.clipboardData

示範地址: http://www.lsproc.com/demo/clipboard/demo.html 

下載:clipbord.zip

另: google code 上有個 zeroclipboard 的項目, 如果想要方便的話, 也可以使用 

地址: http://code.google.com/p/zeroclipboard/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.