当用户以隐身或私人模式浏览时,我试图阻止对我的 WordPress 网站的访问。我的目标是完全阻止隐身模式下的用户查看网站的任何部分
我尝试在 FUnctions.php 中添加这些代码以完全阻止用户访问该网站!
function block_incognito_mode() {
?>
<script>
// Detect incognito mode
function detectIncognito(callback) {
const fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
callback(false);
} else {
fs(window.TEMPORARY, 100, () => callback(false), () => callback(true));
}
}
detectIncognito(function(isIncognito) {
if (isIncognito) {
// Block access by replacing the entire document
document.head.innerHTML = ''; // Clear the head section
document.body.innerHTML = `
<div style="text-align: center; margin-top: 50px; font-family: Arial, sans-serif;">
<h1 style="color: #333;">Access Denied</h1>
<p style="color: #555;">Incognito mode is not allowed on this website.</p>
<p style="color: #999;">Please disable Incognito mode and refresh the page to continue.</p>
</div>`;
document.body.style.backgroundColor = '#f2f2f2';
document.body.style.pointerEvents = 'none'; // Disable all interactions
}
});
</script>
<?php
}
add_action('wp_footer', 'block_incognito_mode');
没有防弹解决方案,但有这个库可以使用和测试。
https://github.com/Joe12387/DetectIncognito