0
点赞
收藏
分享

微信扫一扫

BOM:navigator对象中的userAgent(验证是否为移动端,如果是则跳转至移动端站点)

攻城狮Chova 2022-01-09 阅读 47
<script>
        // 检测 userAgent(浏览器信息)
        !(function () {
            const userAgent = navigator.userAgent
            // 验证是否为Android或iPhone
            const android = userAgent.match(/(Android);?[\s\/]+([\d.]+)?/)
            const iphone = userAgent.match(/(iPhone\sOS)\s([\d_]+)/)
            // 如果是Android或iPhone,则跳转至移动端站点
            if (android || iphone) {
                location.href = 'http://m.itcast.cn'
            }
        })()
</script>
举报

相关推荐

0 条评论