您的位置:首页 > Web前端 > JavaScript

[转载]js复制内容加版权声明代码

2018-02-24 10:23 211 查看
转自:https://www.cnblogs.com/zdz8207/p/js-oncopy.html

1   var ua = navigator.userAgent.toLowerCase();
2     if( window.ActiveXObject ){
3         document.body.oncopy = function(){
4             event.returnValue = false;
5             var t=document.selection.createRange().text;
6             var s=" 原文链接:"+location.href;
7             clipboardData.setData('Text',t+'\r\n'+s);
8         };
9     }else{
10         function addLink(){
11             var body_element = document.getElementsByTagName('body')[0];
12             var selection;
13             selection = window.getSelection();
14             var pagelink = " 原文链接:"+location.href;
15             var copytext = selection + pagelink;
16             var newdiv = document.createElement('div');
17             newdiv.style.position='absolute';
18             newdiv.style.left='-99999px';
19             body_element.appendChild(newdiv);
20             newdiv.innerHTML = copytext;
21             selection.selectAllChildren(newdiv);
22             window.setTimeout(function(){body_element.removeChild(newdiv);},0);
23         }
24         document.oncopy = addLink;
25     }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: