1 <script type="text/javascript">
2 function copyToClipBoard(obj) {
3 var clipBoardContent ="";
4 clipBoardContent += document.getElementById(obj).innerHTML.replace(/<.+?>/gim, '');
5 if (window.clipboardData) {
6 window.clipboardData.clearData();
7 window.clipboardData.setData("Text", clipBoardContent);
8 } elseif (navigator.userAgent.indexOf("Opera") !=-1) {
9 window.location = clipBoardContent;
10 } elseif (window.netscape) {
11 try {
12 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
13 } catch (e) {
14 alert("您的当前浏览器设置已关闭此功能!请按以下步骤开启此功能!\n新开一个浏览器,在浏览器地址栏输入'about:config'并回车。\n然后找到'signed.applets.codebase_principal_support'项,双击后设置为'true'。\n声明:本功能不会危极您计算机或数据的安全!");
15 }
16 var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
17 if (!clip) return;
18 var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
19 if (!trans) return;
20 trans.addDataFlavor('text/unicode');
21 var str =new Object();
22 var len =new Object();
23 var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
24 var copytext = clipBoardContent;
25 str.data = copytext;
26 trans.setTransferData("text/unicode", str, copytext.length *2);
27 var clipid = Components.interfaces.nsIClipboard;
28 if (!clip) returnfalse;
29 clip.setData(trans, null, clipid.kGlobalClipboard);
30 }
31 alert("已成功复制!");
32 returntrue;
33 }
34
35 </script>