首先这篇文章来自lao k,薇晓兰收集整理
代码如下
script>
$(function () {
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 = “薇晓兰博客(blog.weixiaoline.com) – 转载请保留原文链接:” + 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 = “薇晓兰博客(blog.weixiaoline.com) – 转载请保留原文链接:” + 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>
把以上代码
JS代码添加到JS文件中或者在网站底部全文引用。在有人复制我们文章的时候,会在文章末尾加上自带的版权连接,当然如果对方是君子可能会给予留有出处,如果是小人他们肯定会去掉安全。
注意上面的script代码缺少<>,自己不全即可,主要这个主题代码写全,前台不显示不知道是不是bug