AI 赋能应用,代码定义未来
用全新 AI 数字人・智能应用・重构数字体验服务

js复制内容加版权声明代码

发表日期:2025-01-30 浏览次数:2474 来源:javascript学习 编辑:Monster

当别人复制你的文章内容时,会在文章末尾自动添加一个版权声明。网络版权意识薄弱,这个是君子做法,如果真要抄你的文章,声明再多都没用,就像很多网站底部声明一样,几乎是一个摆设,大家也看开了。文章保留所有权利,如果你复制我的文章,没有按照我的声明,说不定哪天我心情好,就会找你聊聊天了……


$("body").on('copy', function (e) {

if (typeof window.getSelection == "undefined") return; //IE8 or earlier...

var body_element = document.getElementsByTagName('body')[0];

var selection = window.getSelection();

//if the selection is short let's not annoy our users

if (("" + selection).length < 30) return;


//create a div outside of the visible area

//and fill it with the selected text

var newdiv = document.createElement('div');

newdiv.style.position = 'absolute';

newdiv.style.left = '-99999px';

body_element.appendChild(newdiv);

newdiv.appendChild(selection.getRangeAt(0).cloneContents());

//we need a <pre> tag workaround

//otherwise the text inside "pre" loses all the line breaks!

if (selection.getRangeAt(0).commonAncestorContainer.nodeName == "PRE") {

newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";

}

newdiv.innerHTML += "<br /><br />原文: <a href='"

+ document.location.href + "'>"

+ document.location.href + "</a> &copy; szhulian.com";

selection.selectAllChildren(newdiv);

window.setTimeout(function () { body_element.removeChild(newdiv); }, 200);

});

本站文章均为深正网站建设摘自权威资料,书籍,或网络原创文章,如有版权纠纷或者违规问题,请即刻联系我们删除,我们欢迎您分享,引用和转载,但谢绝直接搬砖和抄袭!感谢...
关注深正互联
填写电话 ≠ 打扰
只给您多一份选择,少一份顾虑
您可拨打以下电话联系我们技术总监
138 2888 4598
用心将技术和服务
遍布全中国乃至世界...
138-2888-4598
我们坚信无论您在哪里我们都能为您提供优质的服务!
请填写您的需求
您希望我们为您提供什么服务呢
数字人 AI应用 O2O电商 智联AioT APP开发 小程序开发 ERP/CRM系统开发 电脑系统开发
您的预算
3万-5万 5万-8万 8万-10万 10万-15万 15万以上
0.595921s