2022-11-18 本教程在知更鸟最新主题中失效,可能会出现粘贴内容为空。文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
复制自动加入版权内容
实现方法很简单,只需要复制下面代码,放到 footer.php <body>标签内即可文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
代码:文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
<script type="text/javascript">
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
document.body.oncopy = function () {
event.returnValue = false;
var selectedText = document.selection.createRange().text;
var pageInfo = '<br>---------(^-^)---------<br>'
+ '原文链接<br>'+ document.location.href
clipboardData.setData('Text', selectedText.replace(/\n/g, '<br>') + pageInfo);
}
}
else {
function addCopyRight() {
var body_element = document.getElementsByTagName('body')[0];
var selection = window.getSelection();
var pageInfo = '<br>---------(^-^)---------<br>'
+ '原文链接<br>'+ document.location.href
var copyText = selection.toString().replace(/\n/g, '<br>') + pageInfo; // Solve the line breaks conversion issue
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 = addCopyRight;
}
</script>
这段代码实现的方法有很多,可以直接引用,也可以做成JS文件再引用。文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
本文代码可与 添加复制提示弹窗 | 今夕何夕兮 (www.ginc.site) 一起食用。文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
效果图:
文章源自今夕何夕兮-https://www.ginc.site/building-and-development748.html
转载请注明来自:今夕何夕兮
除特别声明外,本站内容遵循 CC-BY-NC-SA4.0 协议授权。部分资源收集于网络,只做学习和交流使用,版权归原作者所有。
提示:
若文章中图片、链接等信息出错,请及时反馈,博主将在第一时间更新。谢谢大家!


中国–北京–北京 1F
代码貌似是通用的,放在Hexo里试试!
中国–山东 B1
@ TeacherDu 是的,这种放在页脚里的都时通用的