Loading... JS 仿知乎复制文章末尾自动添加字符串 当别人复制你的文章内容时,会在文章末尾自动添加一串字符。 将此代码放置在body之前即可 ```html <!--自动添加版权信息 --> <script> $("body").bind('copy', function (e) { if (typeof window.getSelection == "undefined") return; //IE8 及更老的版本不兼容 var body_element = document.getElementsByTagName('body')[0]; var selection = window.getSelection(); //创建一个DIV的可见区域之外 //并填写选定的文本 var newdiv = document.createElement('div'); newdiv.style.position = 'absolute'; newdiv.style.left = '-99999px'; body_element.appendChild(newdiv); newdiv.appendChild(selection.getRangeAt(0).cloneContents()); //我们需要<pre>标签解决方案 //其他的文本在<pre>失去了所有的行符! 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>"; selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200); }); </script> ``` 相关文章 Centos7 完全卸载mysql 成都郫都区:新增本土病例2例 24小时内将完成90余万人采样 [郫县豆瓣加油]多图直击成都郫都区疫情防控现场 成都新公园,418万平方米的公园 大成都5条新线车站齐亮相! 自建php仿新浪短网址服务 马云最新演讲全文2020-9-30 Golang 汇编入门知识总结 【Redis持久化】服务器突然挂了!Redis缓存都在内存中啊 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序 Last modification:June 19th, 2020 at 11:56 pm © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat