应用办法一:
关上以后主题头部模板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文章防复制代码的办法的具体内容,更多请存眷资源魔其它相干文章!
标签: WordPress wordpress教程 wordpress自学 wordpress技术
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。