实现代码如下,说明2点,一是如果你的网站是有jquery-1.10.2.min.js文件,则不需要再次引入; 二是红色部分替换成你的版权信息即可。
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
function copyAppend() {
var addText="作者:白龙<br />链接:https://www.bailong.org.cn/<br />来源:白龙网<br />著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。";
var a = document.getElementsByTagName("body")[0];
var d = document.createElement("div");
d.id = "stcpDiv";
d.style.position = "absolute";
d.style.top = "-1999px";
d.style.left = "-1988px";
a.appendChild(d);
d.innerHTML = "ShareThis Copy and Paste";
if (document.addEventListener) {
a.addEventListener("copy",
function(i) {
if (typeof(Tynt) != "undefined") {
return
}
var h = document.getSelection();
if (h.isCollapsed) {
return
}
var g = h.getRangeAt(0).cloneContents();
d.innerHTML = "";
d.appendChild(g);
if (d.textContent.trim().length == 0) {
return
}
if ((h + "").trim().length == 0) {} else {
if (d.innerHTML == (h + "") || d.textContent == (h + "")) {
d.innerHTML = h + ""+addText;
} else {
d.innerHTML += addText;
}
}
var f = document.createRange();
f.selectNodeContents(d);
var j = h.getRangeAt(0);
h.removeAllRanges();
h.addRange(f);
setTimeout(function() {
h.removeAllRanges();
h.addRange(j)
},
0)
},
false)
} else {
if (document.attachEvent) {}
}
}
$(function(){
copyAppend();
});
</script>