(function() {
// 检测是否为移动设备(手机或平板)
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Windows Phone/i.test(navigator.userAgent);
}
// 检测是否为移动屏幕尺寸(备用方案)
function isMobileScreen() {
return window.innerWidth <= 768;
}
// 如果不在移动设备上,执行阻止访问
if (!isMobileDevice() && !isMobileScreen()) {
// 方法1:完全清空页面内容并显示警告
document.documentElement.innerHTML = '';
document.body.innerHTML = '';
// 创建警告页面
var warningPage = document.createElement('div');
warningPage.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
z-index: 99999;
`;
warningPage.innerHTML = `
<div style="text-align: center; padding: 20px; max-width: 500px;">
<h1 style="color: #d32f2f;">访问受限</h1>
<p style="font-size: 18px; margin: 20px 0;">本页面仅支持移动设备(手机/平板)访问。</p>
<p style="font-size: 14px; color: #666;">请使用手机浏览器扫描二维码访问。</p>
</div>
`;
document.body.appendChild(warningPage);
// 可选:跳转到指定页面(取消注释即可启用)
// window.location.href = 'https://example.com/blocked';
// 阻止后续JavaScript执行
throw new Error('Access denied: Desktop browsers are not allowed');
}
})();
只允许通过手机端访问的js代码
最新推荐文章于 2026-06-29 09:01:58 发布
7053

被折叠的 条评论
为什么被折叠?



