判断移动端(手机)还是客户端(电脑)打开网页并跳转不同页面(首页)

要求:

有时候我们移动端和客户端的首页因为布局问题所以是分开写的,所以下面js代码能实现判断移动端(手机)还是客户端(电脑)打开网页并跳转不同页面。

实现 js代码:

 <script>
 if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
     
     
    window.location.href = "shouji.html";
} else {
     
     
  window.location.href = "zaixian.html";
}
</script>

注意:
window.location.href = " 这里是手机打开网页跳转到的首页的html文件 ";
window.location.href = “这里是电脑打开网页跳转到的首页的html文件”;
js代码可以写在body标签底部;

猜你喜欢

转载自blog.csdn.net/luo1831251387/article/details/110875741
今日推荐