查看效果:js雙擊復(fù)制支持火狐
火狐js雙擊復(fù)制內(nèi)容代碼如下:
function copy(copycontent){
if(window.clipboarddata){
window.clipboarddata.cleardata();
window.clipboarddata.setdata(text, copycontent);
}else if(navigator.useragent.indexof(opera) != -1){
window.location = copycontent;
}else if (window.netscape){
try{
netscape.security.privilegemanager.enableprivilege(universalxpconnect);
}catch (e){
alert(您的當(dāng)前瀏覽器設(shè)置已關(guān)閉此功能!請(qǐng)按以下步驟開啟此功能!\n新開一個(gè)瀏覽器,在瀏覽器地址欄輸入'about:config'并回車。\n然后找
到'signed.applets.codebase_principal_support'項(xiàng),雙擊后設(shè)置為'true'。\n聲明:本功能不會(huì)危極您計(jì)算機(jī)或數(shù)據(jù)的安全!);
}
var clip = components.classes['@mozilla.org/widget/clipboard;1'].createinstance(components.interfaces.nsiclipboard);
if (!clip) return false;
var trans = components.classes['@mozilla.org/widget/transferable;1'].createinstance(components.interfaces.nsitransferable);
if (!trans) return false;
trans.adddataflavor('text/unicode');
var str = new object();
var len = new object();
var str = components.classes[@mozilla.org/supports-string;1].createinstance(components.interfaces.nsisupportsstring);
var copytext = copycontent;
str.data = copytext;
trans.settransferdata(text/unicode,str,copytext.length*2);
var clipid = components.interfaces.nsiclipboard;
if (!clip) return false;
clip.setdata(trans,null,clipid.kglobalclipboard);
}
return true;
}
雙擊復(fù)制textarea內(nèi)容,舉例如下:我這里有jquery的引入。
<script language=javascript src=../js/jquery-1.4.4.min.js></script>
<script language=javascript>
$(function(){
$(textarea[name='other']).dblclick(function(){//雙擊復(fù)制textarea name=other里面的內(nèi)容http://%77%77%77%2e%66網(wǎng)站制作%6f學(xué)習(xí)網(wǎng)%72%61%73%70%2e%63%6e
if(copy($.trim($(this).val())))alert(復(fù)制成功!);
});
});
</script>