欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

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

发布时间:2024/4/15 编程问答 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 [转载]js复制内容加版权声明代码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

转自: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 }

 

转载于:https://www.cnblogs.com/ss977/p/8464359.html

总结

以上是生活随笔为你收集整理的[转载]js复制内容加版权声明代码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。