JavaScript 實現(xiàn)完美兼容多瀏覽器的復制功能代碼
來源:易賢網(wǎng) 閱讀:1093 次 日期:2015-04-29 14:54:02
溫馨提示:易賢網(wǎng)小編為您整理了“JavaScript 實現(xiàn)完美兼容多瀏覽器的復制功能代碼”,方便廣大網(wǎng)友查閱!

分享一段利用 JavaScript 實現(xiàn)復制功能的代碼,兼容多瀏覽器,兼容IE和火狐瀏覽器。

<html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript 復制功能代碼,兼容多瀏覽器</title> </head> <script language="javascript"> copyValue=function(strValue){ if(isIE()){ clipboardData.setData("Text",strValue); alert("您已成功復制了此地址"); }else{ copy(strValue); alert("內(nèi)容已被復制!"); } } function isIE(number){ if(typeof(number)!=number){ return!!document.all; } } function copy(text2copy){ var flashcopier = 'flashcopier'; if(!document.getElementById(flashcopier)){ var divholder = document.createElement('div'); divholder.id = flashcopier; document.body.appendChild(divholder); } document.getElementById(flashcopier).innerHTML = ''; var divinfo = '<embed src="" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//這里是關(guān)鍵 document.getElementById(flashcopier).innerHTML = divinfo; } </script> <div class="phoinfo"> 貼圖地址:<input name="txtPhotoPath" value="" id="txtPhotoPath" type="text" size="65" /> <input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('www.daimajiayuan.com');" value="復制" /> </div> </body> </html>

更多信息請查看IT技術(shù)專欄

更多信息請查看腳本欄目
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)