WordPress 复制内容保护:保护要复制的特定页面并使用 jQuery 和 Javascript 禁用 CTRL+C、CTRL+V

在这里,我向您分享一个代码片段,您可以使用它来保护您要复制的特定页面。 此代码将禁用右键单击、CTRL+C 和 CTRL+V 等。我从 StackOverflow.com 获得此代码并对其进行了一些修改,以便您可以将其用于您的 WordPress 页面。

只需将代码中的页面 ID 更改为您想要保护的页面 ID。

<?php
    if(is_page('YOUR PAGE ID')){?>
<script>
 
jQuery(document).ready(function() {
 jQuery(function() {
       jQuery(this).bind("contextmenu", function(e) {
            e.preventDefault();
        });
    });
});
     
// Disable Right click
document.addEventListener('contextmenu', event => event.preventDefault());
 
// Disable key down
document.onkeydown = disableSelectCopy;
 
// Disable mouse down
document.onmousedown = dMDown;
 
// Disable click
document.onclick = dOClick;
 
function dMDown(e) { return false; }
 
function dOClick() { return true; }
 
function disableSelectCopy(e) {
    // current pressed key
    var pressedKey = String.fromCharCode(e.keyCode).toLowerCase();
    if ((e.ctrlKey && (pressedKey == "c" || pressedKey == "x" || pressedKey == "v" || pressedKey == "a" || pressedKey == "u")) ||  e.keyCode == 123) {
        return false;
    }
}   
     
</script>
<?php } ?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注