WordPress实现复制内容自动加入版权原文链接

WordPress实现复制内容自动加入版权原文链接插图

当你辛苦写的文章,被别人复制了自己的文章,又被不习惯注明原文出处的网友们CV时,那就主动出击吧。下面教你使用一段简单的JS代码实现复制网页中的内容时,就会自动加入版权内容和自动帮助你加上原文出处链接。

简要说明:代码主要通过原生的js来实现,直接将将本站提供的代码放置到网站中的<body></body>内或网页其他合适的位置即可。

实现代码:

<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=" 原文链接:"+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 = " 原文链接:"+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>
<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=" 原文链接:"+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 = " 原文链接:"+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>
<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=" 原文链接:"+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 = " 原文链接:"+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>
© 版权声明
THE END
喜欢点个赞支持一下吧
点赞0赏币 分享
Everyone has its disadvantage just like the god bites the apple. the bigger disadvantage you have, the more the god appreciate it.
每个人都会有缺陷,就像被上帝咬过的苹果,有的人缺陷比较大,正是因为上帝特别喜欢他的芬芳
评论交流 抢沙发

请登录后发表评论

    暂无评论内容