- function copyToClipboard(text){
- if(text==null||text=='undefined')
- return;
-
-
- if (window.clipboardData){
- window.clipboardData.setData("Text", text);
- }
- else if (window.netscape){
- netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
- 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=text;
-
- str.data=copytext;
-
- trans.setTransferData("text/unicode",str,copytext.length*2);
-
- var clipid=Components.interfaces.nsIClipboard;
-
- if (!clip) return ;
-
- clip.setData(trans,null,clipid.kGlobalClipboard);
-
- }else{
- window.alert("不支持该浏览器的复制功能,请手动复制");
- return;
- }
- window.alert("已复制成功,请直接粘贴$codeFormat");
- }
posted @
2008-12-31 16:35
lovingprince
阅读(
237)
评论()
编辑
收藏
举报