js复制内容加版权声明代码
2016-08-02 13:24
323 查看
$("body").bind('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 />Read more at: <a href='" + document.location.href + "'>" + document.location.href + "</a> © MySite.com"; selection.selectAllChildren(newdiv); window.setTimeout(function () { body_element.removeChild(newdiv); }, 200); });
相关文章推荐
- [转载]js复制内容加版权声明代码
- js复制内容加版权声明代码
- JS实现复制网页内容自动加入版权内容代码和原文链接
- 复制网站文章内容时自动添加版权信息的JS代码
- 复制Input内容的js代码_支持所有浏览器,修正了Firefox3.5以上的问题
- js实现当用户复制网页内容时添加版权等额外信息源码
- 禁止网站页面内容被复制的javascript代码,在公共js文件中写入下图中代码(兼容forefox和IE)
- JavaScript实现自动在复制的内容后添加版权声明
- JS将制定内容复制到剪切板示例代码
- js复制内容到剪贴板代码,js复制代码
- 网站内容禁止复制和粘贴、另存为的js代码
- JS复制网页内容自带版权信息
- 表单提交时自动复制内容到剪贴板的js代码
- 表单提交时自动复制内容到剪贴板的js代码
- 复制加上版权及文章地址的js代码
- 一段js代码解决网页内容无法复制的问题
- JS复制内容到剪切板的实例代码(兼容IE与火狐)
- js复制网页内容并兼容各主流浏览器的代码
- 网站内容禁止复制和粘贴、另存为的js代码
- js复制内容到剪贴板代码,js复制代码