admin管理员组文章数量:1320617
So I'm trying to redirect mobile pages on my website. If someone is on a mobile device then it would send them to the mobile site rather than the desktop site. It works on Chrome. However, it is not working on macOS Safari. Any idea why? The JavaScript is below:
<script>
if (screen.width <= 420) {
document.location="mobileindex.html";
}
</script>
So I'm trying to redirect mobile pages on my website. If someone is on a mobile device then it would send them to the mobile site rather than the desktop site. It works on Chrome. However, it is not working on macOS Safari. Any idea why? The JavaScript is below:
<script>
if (screen.width <= 420) {
document.location="mobileindex.html";
}
</script>
Share
Improve this question
edited Mar 2, 2018 at 21:55
toastrackengima
8,7624 gold badges53 silver badges62 bronze badges
asked Mar 2, 2018 at 21:38
Gib CannonGib Cannon
531 silver badge7 bronze badges
1 Answer
Reset to default 10screen.width
returns the width of the screen, not the browser window. This is good as it means that we can't falsely redirect users to the mobile site.
In Chrome, we can test that our logic works using the Device Emulator. When a page is loaded in the Device Emulator, screen.width
returns the width of the device being emulated, rather than the host puter's screen.
However, in Safari, the corresponding Responsive Design Mode does not work this way. screen.width
will always return the width of the puter monitor in Safari, not the width of the emulated device.
In other words, this is a problem with Safari's implementation, not your code. It will work fine on an actual mobile device.
本文标签: javascriptWhy does windowscreen not work on macOS safariStack Overflow
版权声明:本文标题:javascript - Why does window.screen not work on macOS safari - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742077891a2419515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论