點(diǎn)擊進(jìn)行復(fù)制的JS代碼實(shí)例
更新時間:2013年08月23日 15:37:10 作者:
這篇文章介紹了點(diǎn)擊進(jìn)行復(fù)制的JS代碼實(shí)例,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
function copy_clip() {
var url = $("#back_info").html(); //需要復(fù)制的內(nèi)容
var txt = url.substring(url.indexOf(":") + 1, url.length);
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
alert('恭喜,復(fù)制成功!');
} else if (navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("您的firefox安全限制限制您進(jìn)行剪貼板操作,請?jiān)谛麓翱诘牡刂窓诶镙斎?about:config'然后找到'signed.applets.codebase_principal_support'設(shè)置為true'");
return false;
}
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
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 = txt;
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);
}
}
您可能感興趣的文章:
- js實(shí)現(xiàn)點(diǎn)擊按鈕復(fù)制文本功能
- js實(shí)現(xiàn)點(diǎn)擊復(fù)制當(dāng)前文本到剪貼板功能(兼容所有瀏覽器)
- js實(shí)現(xiàn)點(diǎn)擊后將文字或圖片復(fù)制到剪貼板的方法
- JS簡單實(shí)現(xiàn)點(diǎn)擊復(fù)制鏈接的方法
- 用 javascript 實(shí)現(xiàn)的點(diǎn)擊復(fù)制代碼
- JavaScript實(shí)現(xiàn)點(diǎn)擊按鈕就復(fù)制當(dāng)前網(wǎng)址
- JavaScript 點(diǎn)擊觸發(fā)復(fù)制功能實(shí)例詳解
- 原生js實(shí)現(xiàn)點(diǎn)擊按鈕復(fù)制內(nèi)容到剪切板
- JavaScript實(shí)現(xiàn)點(diǎn)擊復(fù)制功能具體代碼(JS訪問剪貼板相關(guān))
相關(guān)文章
JS實(shí)現(xiàn)點(diǎn)擊拉拽輪播圖pc端移動端適配
本文通過實(shí)例代碼給大家介紹了JS點(diǎn)擊拉拽輪播圖pc端移動端適配 ,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09
解析John Resig Simple JavaScript Inheritance代碼
上網(wǎng)也查了一下對些的理解說的都不是很清楚. 在翻閱的同時找到了一篇 分析這篇文章的文章 哈哈 分析的很詳細(xì). (Join Resig 大師的 "Simple Inheritance" 使用了很多有意思的技巧) 如果你有時間, 并對此感興趣不訪好好看看. 我相信多少會有所收益的.2012-12-12

