<div class="codetitle"> <span><a style="CURSOR: pointer" data="57339" class="copybut" id="copybut57339" onclick="doCopy('code57339')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code57339"> <br><script type="text/javascript" language="javascript"> <BR> //复制到剪切板js代码 <BR> function copyToClipBoard(s) { <BR> //alert(s); <BR> if (window.clipboardData) { <BR> window.clipboardData.setData("Text", s); <BR> alert("已经复制到剪切板!"+ "\n" + s); <BR> } else if (navigator.userAgent.indexOf("Opera") != -1) { <BR> window.location = s; <BR> } else if (window.netscape) { <BR> try { <BR> netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); <BR> } catch (e) { <BR> alert("被浏览器拒绝! 请在浏览器地址栏输入'about:config'并回车 然后将'signed.applets.codebase_principal_support'设置为'true'"); <BR> } <BR> var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); <BR> if (!clip) <BR> return; <BR> var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); <BR> if (!trans) <BR> return; <BR> trans.addDataFlavor('text/unicode'); <BR> var str = new Object(); <BR> var len = new Object(); <BR> var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); <BR> var copytext = s; <BR> str.data = copytext; <BR> trans.setTransferData("text/unicode", str, copytext.length * 2); <BR> var clipid = Components.interfaces.nsIClipboard; <BR> if (!clip) <BR> return false; <BR> clip.setData(trans, null, clipid.kGlobalClipboard); <BR> alert("已经复制到剪切板!" + "\n" + s) <BR> } <BR> }</script><br> </div>