zoukankan      html  css  js  c++  java
  • js复制内容加版权声明代码

    1 $("body").on('copy', function (e) { if (typeof window.getSelection == "undefined") return; //IE8 or earlier... var body_element = document.getElementsByTagName('body')[0]; var selection = window.getSelection(); //if the selection is short let's not annoy our users if (("" + selection).length < 30) return; //create a div outside of the visible area //and fill it with the selected text var newdiv = document.createElement('div'); newdiv.style.position = 'absolute'; newdiv.style.left = '-99999px'; body_element.appendChild(newdiv); newdiv.appendChild(selection.getRangeAt(0).cloneContents()); //we need a <pre> tag workaround //otherwise the text inside "pre" loses all the line breaks! if (selection.getRangeAt(0).commonAncestorContainer.nodeName == "PRE") { newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>"; } newdiv.innerHTML += "<br /><br />原文: <a href='" + document.location.href + "'>" + document.location.href + "</a> &copy; caibaojian.com"; selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200); });

    当别人复制你的文章内容时,会在文章末尾自动添加一个版权声明。网络版权意识薄弱,这个是君子做法,如果真要抄你的文章,声明再多都没用,就像我的网站底部声明一样,几乎是一个摆设,我也看开了。文章保留所有权利,如果你复制我的文章,没有按照我的声明,说不定哪天我心情好,就会找你聊聊天了……

    代码来源

  • 相关阅读:
    iOS开发 日常错误积累
    Linux编程---I/O部分
    Binder机制1---Binder原理介绍
    hdu4405概率dp入门
    SSL连接建立过程分析(1)
    用GDB调试程序(一)
    RBAC权限管理
    HDU3930(离散对数与原根)
    Java实现 蓝桥杯VIP 算法提高 特殊的质数肋骨
    Java实现 蓝桥杯VIP 算法提高 产生数
  • 原文地址:https://www.cnblogs.com/qqziyuan8/p/5749046.html
Copyright © 2011-2022 走看看