JS简单判断IOS/安卓/PC客户端并运行指定代码

JS简单判断IOS/安卓/PC客户端并运行指定代码

网小白
2019-03-16 / 0 评论 / 750 阅读 / 正在检测是否收录...

<script>
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { //判断iPhone|iPad|iPod|iOS
//alert(navigator.userAgent);
window.location.href = "iphone.html";//此处更改想要在IOS端运行的JS代码
} else if (/(Android)/i.test(navigator.userAgent)) { //判断Android
//alert(navigator.userAgent);
window.location.href = "android.html";//此处更改想要在安卓端运行的JS代码
} else { //pc
window.location.href = "pc.html";//此处更改想要在PC端运行的JS代码
};
</script>

当然,简单的判断很容易出现个别情况失效的问题,需要更加复杂的js判断跟随,以后有机会会分享的。

0

评论 (0)

取消