码迷,mamicode.com
首页 > Web开发 > 详细

JS实现复制网页内容自动加入版权内容代码和原文链接

时间:2019-04-21 09:52:53      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:func   pen   html   script   ati   doc   ofo   new   ase   

<script type="text/javascript"> var Sys = {}; var ua = navigator.userAgent.toLowerCase(); if( window.ActiveXObject ){ document.body.oncopy = function(){ event.returnValue = false; var t=document.selection.createRange().text; var s=" 原文链接:"+location.href; clipboardData.setData(‘Text‘,t+‘\r\n‘+s); }; }else{ function addLink(){ var body_element = document.getElementsByTagName(‘body‘)[0]; var selection; selection = window.getSelection(); var pagelink = " 原文链接:"+location.href; var copytext = selection + pagelink; var newdiv = document.createElement(‘div‘); newdiv.style.position=‘absolute‘; newdiv.style.left=‘-99999px‘; body_element.appendChild(newdiv); newdiv.innerHTML = copytext; selection.selectAllChildren(newdiv); window.setTimeout(function(){body_element.removeChild(newdiv);},0); } document.oncopy = addLink; } </script>

在html文件里面复制上面代码,粘贴到/body代码前面
聚客网络

JS实现复制网页内容自动加入版权内容代码和原文链接

标签:func   pen   html   script   ati   doc   ofo   new   ase   

原文地址:https://blog.51cto.com/14296754/2381873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!