严选品质
正规商家

如何实现复制网页内容自动添加版权信息?

将以下代码添加页脚的 </body> 前面即可:

  1.    <script type=“text/javascript”>
  2.    function addLink() {
  3.     var selection = window.getSelection();
  4.     pagelink = “. 原文出自[国外主机测评] 转载请保留原文链接: “ + document.location.href;
  5.     copytext = selection + pagelink;
  6.     newdiv = document.createElement(‘div’);
  7.     newdiv.style.position = ‘absolute’;
  8.     newdiv.style.left = ‘-99999px’;
  9.     document.body.appendChild(newdiv);
  10.     newdiv.innerHTML = copytext;
  11.     selection.selectAllChildren(newdiv);
  12.     window.setTimeout(function () {
  13.         document.body.removeChild(newdiv);
  14.     }, 100);
  15. }
  16. document.oncopy = addLink;
  17. </script>

对于DUX主题,可以添加在主题设置中:

如何实现复制网页内容自动添加版权信息?

以上代码适用于 WordPress 或 zblog 等站点,如果是 zblog 站点,记得在后台点击[清空缓存并重新编译模板]才行哦。

赞(0)
未经允许不得转载:主机推广 » 如何实现复制网页内容自动添加版权信息?