使用要领一:
翻开当前主题头部模板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>
使用要领二:
上面的要领检察源代码时有些乱,能够在当前主题目录新建一个名称为copyright.js文件,将下面代码增加进去:
// 制止右键 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后,将落空结果。
以上就是WordPress文章防复制代码的要领的细致内容,更多请关注ki4网别的相干文章!