javascript获取本页面URL地址
点击复制,获取本页面URL地址,支持IE、谷歌。
1 <script type="text/javascript">
2 var clipBoardContent=document.location;
3 clipBoardContent+='\r\n';
4 function copy_clip(meintext)
5 {
6 if (window.clipboardData)
7 {
8 window.clipboardData.setData("Text", meintext);
9 }
10 else if (window.netscape)
11 {
12 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
13 var clip = Components.classes['@mozilla.org/widget/clipboard;1']
14 .createInstance(Components.interfaces.nsIClipboard);
15 if (!clip) return;
16 var trans = Components.classes['@mozilla.org/widget/transferable;1']
17 .createInstance(Components.interfaces.nsITransferable);
18 if (!trans) return;
19 trans.addDataFlavor('text/unicode');
20
21 var str = new Object();
22 var len = new Object();
23
24 var str = Components.classes["@mozilla.org/supports-string;1"]
25 .createInstance(Components.interfaces.nsISupportsString);
26
27 var copytext=meintext;
28
29 str.data=copytext;
30
31 trans.setTransferData("text/unicode",str,copytext.length*2);
32
33 var clipid=Components.interfaces.nsIClipboard;
34
35 if (!clip) return false;
36
37 clip.setData(trans,null,clipid.kGlobalClipboard);
38
39 }
40 return false;
41 }
42
43 var o = clipBoardContent;
44 function copyURL()
45 {
46 copy_clip(o);
47
48 alert("复制成功!");
49 }
50 </script>
2 var clipBoardContent=document.location;
3 clipBoardContent+='\r\n';
4 function copy_clip(meintext)
5 {
6 if (window.clipboardData)
7 {
8 window.clipboardData.setData("Text", meintext);
9 }
10 else if (window.netscape)
11 {
12 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
13 var clip = Components.classes['@mozilla.org/widget/clipboard;1']
14 .createInstance(Components.interfaces.nsIClipboard);
15 if (!clip) return;
16 var trans = Components.classes['@mozilla.org/widget/transferable;1']
17 .createInstance(Components.interfaces.nsITransferable);
18 if (!trans) return;
19 trans.addDataFlavor('text/unicode');
20
21 var str = new Object();
22 var len = new Object();
23
24 var str = Components.classes["@mozilla.org/supports-string;1"]
25 .createInstance(Components.interfaces.nsISupportsString);
26
27 var copytext=meintext;
28
29 str.data=copytext;
30
31 trans.setTransferData("text/unicode",str,copytext.length*2);
32
33 var clipid=Components.interfaces.nsIClipboard;
34
35 if (!clip) return false;
36
37 clip.setData(trans,null,clipid.kGlobalClipboard);
38
39 }
40 return false;
41 }
42
43 var o = clipBoardContent;
44 function copyURL()
45 {
46 copy_clip(o);
47
48 alert("复制成功!");
49 }
50 </script>
1 <a href="#" onclick="copyURL()" style="text-decoration: none">[推荐好友]</a>
2
2
作者:Mr S.R Lee
出处:http://www.cnblogs.com/LeeYongze
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.