如何检测用户是否在移动设备上并将其重定向到移动网站?

问题描述 投票:1回答:2

我有2个网站,并希望让某人在移动设备上自动重定向到该网站。

我看了几个网站和视频,但我无法让它们发挥作用

我希望将移动用户重定向到移动网站,并让PC / Mac用户保持在正常网站上。

html css mobile
2个回答
1
投票

您可以检查屏幕尺寸是否小于699。

<script type="text/javascript">
    if (screen.width <= 699) {
        document.location = "mobile.html";
    }
</script>

3
投票

您可以使用简单的JavaScript代码。

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ) {
 //code to be executed on mobile
}
© www.soinside.com 2019 - 2024. All rights reserved.