这篇文章介绍了复制到剪切板js代码
有需要的朋友可以参考需要
复制代码 代码如下:
<script type="text/javascript" language="javascript">
//复制到剪切板js代码
function copyToClipBoard(s) {
//alert(s);
if (windowclipboardData) {
windowclipboardDatasetData("Text" s);
alert("已经复制到剪切板!"+ "n" + s);
} else if (navigatoruserAgentindexOf("Opera") != ) {
windowlocation = s;
} else if (windownetscape) {
try {
netscapesecurityPrivilegeManagerenablePrivilege("UniversalXPConnect");
} catch (e) {
alert("被浏览器拒绝!n请在浏览器地址栏输入about:config并回车n然后将signedappletscodebase_principal_support设置为true");
}
var clip = Componentsclasses[@mozillaorg/widget/clipboard;]createInstance(ComponentsinterfacesnsIClipboard);
if (!clip)
return;
var trans = Componentsclasses[@mozillaorg/widget/transferable;]createInstance(ComponentsinterfacesnsITransferable);
if (!trans)
return;
transaddDataFlavor(text/unicode);
var str = new Object();
var len = new Object();
var str = Componentsclasses["@mozillaorg/supportsstring;"]createInstance(ComponentsinterfacesnsISupportsString);
var copytext = s;
strdata = copytext;
transsetTransferData("text/unicode" str copytextlength * );
var clipid = ComponentsinterfacesnsIClipboard;
if (!clip)
return false;
clipsetData(trans null clipidkGlobalClipboard);
alert("已经复制到剪切板!" + "n" + s)
}
}</script>