代码
//复制贴到我们的单独JS文件中 laobuluo.com
document.oncontextmenu = 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;
}
};
if (parent.frames.length > 0) top.location.replace(document.location);
可以自己将代码命名,这里我们将它命名为:copyrightpro.js
之后将下方代码添加到当前主题的functions.php
//防止复制文章代码版 laobuluo.com
function copyrightpro_scripts() {
wp_enqueue_script( 'copyrightpro', get_template_directory_uri() . '/js/copyrightpro.js', array(), false );
}
if (! current_user_can('level_10') ) {
add_action( 'wp_enqueue_scripts', 'copyrightpro_scripts' );
}
添加之后,管理员不受到影响,而普通用户无法复制,右键等操作!