兼容IE、Firefox和Chrome的复制内容添加网址版权的代码:
<script type=”text/javascript”>
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject){
document.body.oncopy=function(){
event.returnValue=false;
var t=document.selection.createRange().text;
var s="本文来自:佛商网/www.foshang.net ; 原文链接:"+document.location.href+" ";
clipboardData.setData('Text',t+'\r\n'+s);
}
}
else {
function addLink() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var pagelink = " 本文来自: 佛商网/www.foshang.net ;原文链接:"+document.location.href+" ";
var copytext = selection + pagelink;
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 = addLink;
}
</script>
相关文章
导航栏滚动到一定高度改变背景色JS代码2019-04-03
js屏蔽ip(地区)访问某个静态或动态页面2013-10-09
js根据浏览器版本显示不同内容2013-06-22
js判断浏览器版本(IE,FF,Chrome,Opear,Safari) 2013-05-03
最顶层div遮不住JS及Flash的处理方法2009-07-06
JavaScript 下拉菜单 2009-05-09