對於非ie浏覽器他是用flash來實現的,js代碼如下:
復制代碼 代碼如下:
<script type="text/javascript">
function copy_code(copyText)
{
if (window.clipboardData)
{
window.clipboardData.setData("Text", copyText)
}
else
{
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="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashcopier).innerHTML = divinfo;
}
alert('copy成功!');
}
</script>
<input id="inputTest" type="button" value="測試" onclick="copy_code('拷貝成功!')" />
那個flash文件從這裡下載:下載