| js实现复制内容到剪贴板,可兼容ie和火狐浏览器 |
| 来源:
发布时间:2008-07-23 发布人:
浏览:
人次
字体:
[大
中
小]
|
|
本站提供的这个复制内容到剪贴板的功能是兼容ie及火狐浏览器的,直接点击"复制"按钮就可以保存到系统剪贴板,下面这是网页特效代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <script type="text/javascript"> // <![CDATA[ function copy_clip(copy){ if (window.clipboardData){ window.clipboardData.setData("Text", copy);} 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=copy; 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("已复制"+copy) return false; } // ]]> </script> <h1>请另存代码测试</h1> <input type="text" id="ff" value="www.itwis.com" /><button onclick="copy_clip(document.getElementById('ff').value)">复制 </button>
| |
| |
|
|
|
|
| §最新评论:(评论内容只代表网友观点,与本站立场无关!) | |
|
|
|
|
| 注意:请勿在本站发布政治话题、色情及违反法律的内容。 |
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。 |