国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Firefox中通過JavaScript復制數據到剪貼板(Copy to Clipboard 跨瀏覽器版)

2024-05-06 15:56:02
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了irefox中通過JavaScript復制數據到剪貼板的方法,可以跨瀏覽器使用,大家可以使用看看

復制代碼 代碼如下:


<!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="YES!B/S!" />
<meta content="This page is from " />
<title>CSS/Javascript demo</title>
<script type="text/javascript" language="javascript" >
    function test(){
        copyToClipboard("dddd");
    }
    copyToClipboard = function(txt) {
if(window.clipboardData) {
   window.clipboardData.clearData();
   window.clipboardData.setData("Text", txt);
} else if(navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("您的firefox安全限制限制您進行剪貼板操作,請打開'about:config'將signed.applets.codebase_principal_support'設置為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);
}
}
</script>
</head>
<body>
 <button>復制到粘貼板</button>
</body>
</html>

說明:Firefox的默認安全限制不允許通過JavaScript復制到剪貼板,需要提示用戶修改Firefox的設置。修改方法是打開"about:config"將"signed.applets.codebase_principal_support"設置為"true"。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 汶川县| 钟祥市| 易门县| 中宁县| 同仁县| 鹿泉市| 连云港市| 宾阳县| 宜阳县| 宕昌县| 德安县| 米林县| 大洼县| 锦州市| 五大连池市| 晋宁县| 漾濞| 光山县| 柯坪县| 定襄县| 柳州市| 嘉鱼县| 宝丰县| 安泽县| 左云县| 新兴县| 梁平县| 蒲江县| 都昌县| 营山县| 翁牛特旗| 海淀区| 灵丘县| 怀远县| 都匀市| 即墨市| 九台市| 马关县| 云和县| 颍上县| 商河县|