像现在许多 IT 人士都会写博客,不过有一点不好的地方就是好多人转载别人的原创文章都不注明转载已经转载自哪里,这对原创作者也是不太友好的行为。
韩万隆在这里就针对 wordpress 网站而言,可以做到一些小防范的功能。比如博主我就设置了这样的一个措施,只有登录后才能复制,不登录的访客只能查看,不能右键选择,也不能复制的!好了接下来说一下如何实现这样的功能的。
在这之前,我的网站是有这两个功能的,一个是禁止复制,一个是复制弹窗提醒。代码内容是放在 footer.php 文件里面的,代码分别如下:
#复制弹窗提醒 <script type="text/javascript">function warning(){ if(navigator.userAgent.indexOf("MSIE")>0) { art.dialog.alert('复制成功,若要转载请务必保留原文链接,谢谢合作!'); } else { alert("复制成功,若要转载请务必保留原文链接,谢谢合作!"); }}document.body.oncopy=function(){warning();}</script>
#禁止复制 <?php if (!is_user_logged_in()){ echo '<script type="text/Javascript">document.oncontextmenu=function(e){return false;};document.onselectstart=function(e){return false;};</script><style>body{ -moz-user-select:none;}</style><SCRIPT LANGUAGE=javascript>if (top.location != self.location)top.location=self.location;</SCRIPT><noscript><iframe src=*.html></iframe></noscript>'; } ?>
把以下代码加入到 footer.php 中某个位置 body 之前哦。:
<script type="text/javascript">function warning(){ if(navigator.userAgent.indexOf("MSIE")>0) { art.dialog.alert('复制成功,若要转载请务必保留原文链接,谢谢合作!'); } else { alert("复制成功,若要转载请务必保留原文链接,谢谢合作!"); }}document.body.oncopy=function(){warning();}</script> <?php if (!is_user_logged_in()){ echo '<script type="text/Javascript">document.oncontextmenu=function(e){return false;};document.onselectstart=function(e){return false;};</script><style>body{ -moz-user-select:none;}</style><SCRIPT LANGUAGE=javascript>if (top.location != self.location)top.location=self.location;</SCRIPT><noscript><iframe src=*.html></iframe></noscript>'; } ?>
有兴趣的小伙伴们赶紧试试噢,效果好的话给我反馈反馈!
文章还不错支持一下