将代码添加到网页head 头部,WordPress主题可以将代码添加到头部模板header.php:<?php wp_head(); ?>
,上面即可。
不要忘记将代码放在
- <script =“text/javascript”> 代码 </script>
代码一
- function addLink() {
- var selection = window.getSelection();
- pagelink = “. 原文出自[xz] 转载请保留原文链接: “ + document.location.href;
- copytext = selection + pagelink;
- newdiv = document.createElement(‘div’);
- newdiv.style.position = ‘absolute’;
- newdiv.style.left = ‘-99999px’;
- document.body.appendChild(newdiv);
- newdiv.innerHTML = copytext;
- selection.selectAllChildren(newdiv);
- window.setTimeout(function () {
- document.body.removeChild(newdiv);
- }, 100);
- }
- document.oncopy = addLink;
代码二
- function addLink() {
- var body_element = document.body;
- var selection;
- selection = window.getSelection();
- if (window.clipboardData) { // Internet Explorer
- var pagelink =“rnrn 原文出自[xz ] 转载请保留原文链接: “+document.location.href+“”;
- var copytext = selection + pagelink;
- window.clipboardData.setData (“Text”, copytext);
- return false;
- } else {
- var pagelink = ” 原文出自[ xz ] 转载请保留原文链接: “+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;
添加以上代码后,别人在你网站复制任何文字内容,粘贴时都会自动带上版权信息,使用时修改其中的版本信息,貌似不支持低版本IE。
正文完