兼容问题-浏览器内核不一样
function copyToClipboard(txt) {if (windowclipboardData) {
windowclipboardDataclearData();
windowclipboardDatasetData("Text", txt);
alert("复制成功!")
} else if (navigatoruserAgentindexOf("Opera") != -1) {
windowlocation = txt;
alert("复制成功!");
} else if (windownetscape) {
try {
netscapesecurityPrivilegeManagerenablePrivilege("UniversalXPConnect");
} catch (e) {
alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signedappletscodebase_principal_support'设置为'true'");
}
var clip = Componentsclasses['@mozillaorg/widget/clipboard;1']createInstance(ComponentsinterfacesnsIClipboard);
if (!clip)
return;
var trans = Componentsclasses['@mozillaorg/widget/transferable;1']createInstance(ComponentsinterfacesnsITransferable);
if (!trans)
return;
transaddDataFlavor('text/unicode');
var str = new Object();
var str = Componentsclasses["@mozillaorg/supports-string;1"]createInstance(ComponentsinterfacesnsISupportsString);
var copytext = txt;
strdata = copytext;
transsetTransferData("text/unicode", str, copytextlength 2);
var clipid = ComponentsinterfacesnsIClipboard;
if (!clip)
return false;
clipsetData(trans, null, clipidkGlobalClipboard);
alert("复制成功!")
}else if(copy){
copy(txt);
alert("复制成功!")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)