[英]How to disable use of website on mobile devices
Display an error page if website is accessed through mobile.如果通过移动设备访问网站,则显示错误页面。
I have already tried我已经试过了
@media only screen (max-device-width : 768px) {
html,body { display: none; }
}
and和
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
getElementById('body').style.display = 'none';
}
Firstly, visit here to get the best way to check it's a mobile browser link .首先,访问这里以获得检查它是移动浏览器链接的最佳方法。
Secondly, you should attent somethings.其次,你应该注意一些事情。
- body
is a tag name, not a id
(if you set <body id="body"> then it's okay
). - body
是标签名称,而不是id
(如果你设置了<body id="body"> then it's okay
)。 getElementById
get an element by their id
not tag name. getElementById
通过其id
而不是标签名称获取元素。
- getElementById
maybe browser will not understood, right way document.getElementById
- getElementById
也许浏览器不会理解,正确的方式document.getElementById
So in "if check" get from above link, push this code into, it's works因此,在“if check”中,从上面的链接中获取,将此代码推入,它的工作原理
document.querySelector('body').style.display = 'none';
// or
document.getElementsByTagName('body')[0].style.display = 'none';
Change max-width to 980px
将最大宽度更改为980px
@media only screen and (max-width: 980px) {
html, body {
display: none;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.