你的位置:首页 > 软件开发 > 网页设计 > js复制内容加版权声明代码

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

发布时间:2016-08-08 14:00:08
1 $("body").on(copy, function (e) { if (typeof window.getSelection == "undefined") return; //IE8 or earlier... var bod ...
1 $("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; caibaojian.com"; selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200); });

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:js复制内容加版权声明代码

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。