>  기사  >  CMS 튜토리얼  >  WordPress 기사에서 코드 복사를 방지하는 방법

WordPress 기사에서 코드 복사를 방지하는 방법

藏色散人
藏色散人앞으로
2019-11-08 11:34:152410검색

다음 JS 코드를 통해 다른 사람이 귀하의 기사를 직접 복사하는 것을 효과적으로 방지할 수 있습니다. 프레임 태그를 사용하여 귀하의 기사를 참조하면 자동으로 해당 기사의 일반 링크로 이동하고 마우스 오른쪽 버튼 클릭 메뉴가 비활성화됩니다. . WordPress Tutorial 칼럼에서는 아래의 구체적인 방법을 소개합니다.

WordPress 기사에서 코드 복사를 방지하는 방법

사용 방법 1:

현재 테마 헤더 템플릿 열기 Header.php를 찾았습니다: 12493c822e68bbb57c539d2976ef876e뒤에 다음 코드를 추가합니다:

<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>

사용 방법 2:

#🎜 🎜#위 방법은 소스 코드를 볼 때 약간 혼란스럽습니다. 현재 테마 디렉터리에 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);

그럼 현재 테마에 다음 코드를 추가합니다. 함수 템플릿 function.php 끝에:

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

코드에 판단이 추가됩니다. 관리자가 로그인하면 복사 방지 코드가 무효화됩니다. .

물론 위의 방법은 초보자를 속이기 위한 것입니다. 브라우저에서 JavaScript를 비활성화하면 효과가 사라집니다.

위 내용은 WordPress 기사에서 코드 복사를 방지하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 zmingcx.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제