查看效果: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)閉此功能!請按以下步驟開啟此功能!\n新開一個瀏覽器,在瀏覽器地址欄輸入'about:config'并回車。\n然后找
到'signed.applets.codebase_principal_support'項(xiàng),雙擊后設(shè)置為'true'。\n聲明:本功能不會危極您計(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>
更多信息請查看IT技術(shù)專欄