<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/ 1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>复制内容到剪切板( 兼容ie8 ff ie6)</title>
</head><body>
<script>
//复制内容到剪切板
function copytoclipboard(txt)
{
if(txt==null || txt=='') {
alert("没有选择任何内容!");
return;
}
if(window.clipboarddata)
{
window.clipboarddata.cleardata();
window.clipboarddata.setdata("text", txt);
}
else if(navigator.useragent.indexof('opera') != -1)
{
window.location = txt;
}
else
{
try {
netscape.security.privilegemanager.enableprivilege("universalxpconnect");
} catch (e) {
alert("被浏览器拒绝!n请在浏览器地址栏输入'about:config'并回车n然后将'signed.applets.codebase_principal_support'设置为'true'");
}
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>
</body>
</html>