zoukankan      html  css  js  c++  java
  • JavaScript实现文章复制加版权信息

      

      function addLink() {
          var body_element = document.getElementsByTagName('body')[0];
          var selection;
      if(window.getSelection){//DOM,FF,Webkit,Chrome,IE10
      selection = window.getSelection();
      alert("文字复制成功!若有文字残缺请用右键复制
    转载请注明出处:"+document.location.href);
    
      }else if(document.getSelection){//IE10
      selection= document.getSelection();
      alert("文字复制成功!若有文字残缺请用右键复制
    转载请注明出处:"+document.location.href);
    
      }else if(document.selection){//IE6+10-
      selection= document.selection.createRange().text;
      alert("文字复制成功!若有文字残缺请用右键复制
    转载请注明出处:"+document.location.href);
      }else{
      selection= "";
      alert("浏览器兼容问题导致复制失败!");
      }
          var pagelink = "<br /><br /> 转载请注明来源: <a href='"+document.location.href+"'>"+document.location.href+"</a>";
          var copy_text = selection + pagelink;
          var new_div = document.createElement('div');
          new_div.style.left='-99999px';
          new_div.style.position='absolute';
          body_element.appendChild(new_div );
          new_div.innerHTML = copy_text ;
          selection.selectAllChildren(new_div );
          window.setTimeout(function() {
              body_element.removeChild(new_div );
          },0);
      }
      document.body.oncopy = addLink;
    

      

  • 相关阅读:
    各种排序(二)
    各种排序(一)
    【游记】CSP-S2019游记
    【题解】hdu1506 Largest Rectangle in a Histogram
    【题解】CF161B Discounts
    【CSP-S膜你考】我们的可可西里
    Bzoj3675 [Apio2014]序列分割
    Bzoj3853 GCD Array
    Bzoj3876 [Ahoi2014]支线剧情
    Bzoj2324 [ZJOI2011]营救皮卡丘
  • 原文地址:https://www.cnblogs.com/alone2015/p/5763606.html
Copyright © 2011-2022 走看看