兼容IE、Firefox和Chrome的复制内容添加网址版权的代码

2013-08-24 浏览:1478
兼容IE、Firefox和Chrome的复制内容添加网址版权的代码
评论:(0)复制地址

兼容IE、Firefox和Chrome的复制内容添加网址版权的代码:

 

<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="本文来自:佛商网/www.foshang.net ; 原文链接:"+document.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 = " 本文来自: 佛商网/www.foshang.net ;原文链接:"+document.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>

评论:(0)复制地址
发布:苗景云 | 分类:IT技术&设计 | Tags:JS

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。