探索建站和运维乐趣

WordPress防止文章被复制 - 文章禁止复制和鼠标右键点击

我们很多认真做网站写博客的朋友会发现,自己辛苦的内容被人复制,甚至复制过去不注明出处,且还表明自己的是作者版权所有,是不是很气人?我们一般的做法就是采用一些技术手段提高复制文章的难度,比如限制右键或者是复制功能,这样稍微的给对方增加复制难度。在这里,我们就一起分享这个办法。

这里需要提到的,我们也可以使用WordPress平台有网友分享的免费和付费的防止复制和右键的插件,在这里我们不用插件。

第一、创建JS文件

    // 禁止右键 Laobuluo.com
    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);

   //禁止F12 By cnwper.com
   document.onkeydown = document.onkeyup = document.onkeypress = function(event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if (e && e.keyCode == 123) {
            mAlert();
            e.returnValue = false;
            return (false);
    }
}

这里,我们创建一个自己目录的/inc/copyright.js文件,记得保存位置。

第二、主题调用文件

    function copyrightpro_scripts() {
    	wp_enqueue_script( 'copyright', get_template_directory_uri() . '/inc/copyright.js', array(),  false );
    }
     
    if (! current_user_can('level_10') ) {
    add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' );
    }

这里我们在当前主题中的Functions.php文件中引用即可。实际上我们不想用代码的话,也可以使用我们的WPCopyRights插件直接可视化设置,而且功能更多。

赞(0)
转载保留:老部落 » WordPress防止文章被复制 - 文章禁止复制和鼠标右键点击


关注公众号『老蒋朋友圈』

获取更多建站运营运维新知!
互联网创业、前沿技术......