当前日期时间
当前时间:
网站标志
Logo
全站搜索
广告位
phpweb图片广告
广告位
phpweb图片广告
自定内容

phpweb已经是国内最强的的开源电子商务系统了,但并非完美,因为任何...

互联网3年一轮回,京东凡客等电商品牌在三年之前也不过是小打小闹,而如...

电商已经成为趋势,传统行业的竞争已经逐渐演变到网络上,也有不少用Weboss...

phpweb系统是固定的模式,适用于大部分行业与需求。但有一些行业还是有自己...

当前位置
文章正文

非插件实现WordPress文章防复制和禁止右键菜单

发表:管理员  发表时间:2021-07-12 10:06:35   阅读:(911)次  

使用草莓互联站长提供的WordPress非插件文章防复制JS代码,可以有效地防止别人直接复制拷贝你的文章,用frame标签引用你的文章时,会自动跳转到文章正常链接,同时禁止右键菜单。但是以下代码仅供参考,毕竟从技术层面来说,只防君子,不防小人!从体验来说,体验不是很好,毕竟互联网本来就是分享的价值观!

image.png


代码一


打开当前主题头部模板header.php找到:<?php wp_head(); ?>将下面代码添加到后面:

<script>

// 禁止右键

document.oncontextmenu = function() {

return false

};

// 禁止图片拖放

document.ondragstart = function() {

return false

};

// 禁止选择文本

document.onselectstart = function() {

if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") return false;

else return true;

};

if (window.sidebar) {

document.onmousedown = function(e) {

var obj = e.target;

if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") return true;

else return false;

}

};

// 禁止frame标签引用

if (parent.frames.length > 0) top.location.replace(document.location);

</script>

代码二

// 禁止右键

document.oncontextmenu = function() {

return false

};

// 禁止图片拖放

document.ondragstart = function() {

return false

};

// 禁止选择文本

document.onselectstart = function() {

if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") return false;

else return true;

};

if (window.sidebar) {

document.onmousedown = function(e) {

var obj = e.target;

if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") return true;

else return false;

}

};

// 禁止frame标签引用

if (parent.frames.length > 0) top.location.replace(document.location);

然后再将下面代码添加到当前主题函数模板functions.php的最后:

function copyrightpro_scripts() {

wp_enqueue_script( 'copyright', get_template_directory_uri() . '/copyright.js', array(), false );

}

if (! current_user_can('level_10') ) {

add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' );

}

代码中加了判断,管理员登录状态一下,防复制代码无效。

当然上面的方法,也只是忽悠一下小白,浏览器禁用JavaScript后,将失去效果。草莓互联不建议大家使用JS防复制,很多站点是技术文章,代码都复制不了,那还看什么?除非你的文章价值千金咯。而且真相采集,方法多得是。所以仅供参考学习,不建议使用!


 

假如我们资讯/文章对您有所帮助,您可以通过扫描捐赠二维码支持一下我们~

感谢您对我们的支持,您的小小支持让我们有信心走得更远!

脚注信息
© 2005-2015 草莓互联(100cm.cn) 广州同福信息科技有限公司 版权所有,并保留所有权利。

广州市东莞庄一横路116号 粤ICP备11046216号

经营性网站备案信息 广州网络警察报警平台 不良信息举报中心  百度信誉档案 广州工商红盾网 可信网站认证