本文介绍了不适用于Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我找到了以下脚本来将文本复制到客户端剪贴板,但 它在Firefox中不起作用(在IE 6中正常工作)。有人可以建议我需要更改吗? ===================== ============================ function copy_clip(mytext){ if(window.clipboardData) { // IE window.clipboardData.setData(" Text",mytext); // Netscape } else if(window.netscape) { netscape.security.PrivilegeManager.enablePrivilege(''UniversalXPConnect''); var clip = components.classes [''@ mozilla.org/widget /clipboard;1''].createInstance(Components.interfaces.nsIClipboard); 如果(!clip)返回; // var trans = Components.classes [''@ mozilla.org/widget/transferable;1''].createInstance(Components.interfaces.nsITransfera ble); 如果(!trans)返回; // trans.addDataFlavor(''text / unicode''); // var str = new Object(); var len = new Object(); var str = Components.classes [" @ mozilla.org / supports-string; 1"]。createInstance(Components.interfaces.nsISupportsS tring); var copytext = mytext; str.data = copytext; trans.setTransferData(" text / unicode",str,copytext.length * 2); var clipid = Components.interfaces.nsIClipboard; if(!clip)返回false; clip.setData(trans,null,clipid.kGlobalClipboard); } alert( 以下信息已复制到剪贴板:\ nn \ n" + mytext); 返回false; } ================== ========================I found the following script to copy text to the client clipboard butit is not working in Firefox (works fine in IE 6). Can anyone suggestwhat I need to change?=================================================function copy_clip(mytext){if (window.clipboardData){// IEwindow.clipboardData.setData("Text", mytext);// Netscape}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.nsITransfera ble);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.nsISupportsS tring);var copytext=mytext;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);}alert("Following info was copied to your clipboard:\n\n" + mytext);return false;}==========================================推荐答案 wa *** @ wengert.org 写道:我发现以下脚本将文本复制到客户端剪贴板但是它在Firefox中不起作用(在IE 6中工作正常)。任何人都可以建议我需要改变什么? ============================= ==================== 函数copy_clip(mytext){ if(window.clipboardData) I found the following script to copy text to the client clipboard but it is not working in Firefox (works fine in IE 6). Can anyone suggest what I need to change? ================================================= function copy_clip(mytext){ if (window.clipboardData) 在非IE浏览器中试试这个: alert(window.clipboardData) 你很可能得到''undefined'' 。 Firefox等人不支持 复制到剪贴板。 [...] - RobTry this in non-IE browsers:alert( window.clipboardData )You will most likely get ''undefined''. Firefox et al don''t supportcopying to the clipboard.[...]--Rob谢谢。这正是发生的事情。 所以,我需要检测那些浏览器并禁用剪贴板选项吗? Wayne " RobG" < RG *** @ iinet.net.auau>在消息中写道 news:42 ********************** @ per-qv1-newsreader-01.iinet.net.au ...Thanks. That is exactly what happened.So, I need to detect those browsers and disable the clipboard options?Wayne"RobG" <rg***@iinet.net.auau> wrote in messagenews:42**********************@per-qv1-newsreader-01.iinet.net.au... wa***@wengert.org 写道:我发现以下脚本将文本复制到客户端剪贴板但是它在Firefox中不起作用(在IE 6中工作正常)。任何人都可以建议我需要改变什么? ============================= ==================== 函数copy_clip(mytext){ if(window.clipboardData) I found the following script to copy text to the client clipboard but it is not working in Firefox (works fine in IE 6). Can anyone suggest what I need to change? ================================================= function copy_clip(mytext){ if (window.clipboardData) alert(window.clipboardData) 你很可能会''未定义''。 Firefox等人不支持复制到剪贴板。 [...] - Rob Try this in non-IE browsers: alert( window.clipboardData ) You will most likely get ''undefined''. Firefox et al don''t support copying to the clipboard. [...] -- Rob对于Firefox,还有另一种选择。 看看 http://www.xulplanet.com/tutorials/xultu/clipboard.htmlFor Firefox, there is an alternative.Take a look at http://www.xulplanet.com/tutorials/xultu/clipboard.html 这篇关于不适用于Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 05-29 12:20