代码

JavaScript | 复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function is_pc(){
    var os = new Array("Android","iPhone","Windows Phone","iPod","BlackBerry","MeeGo","SymbianOS");  // 其他类型的移动操作系统类型,自行添加
    var info = navigator.userAgent;
    var len = os.length;
    for (var i = 0; i < len; i++) {
        if (info.indexOf(os[i]) > 0){
            return false
        }
    }
    return true;
}
 
// 如果是移动设备就直接跳转到手机网站页面
if(!is_pc()){
    window.location.href="手机页面链接地址";
}

 

还有一种:

JavaScript | 复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var isMobile = {  
    Android: function() {  
        return navigator.userAgent.match(/Android/i) ? true false;  
    },  
    BlackBerry: function() {  
        return navigator.userAgent.match(/BlackBerry/i) ? true false;  
    },  
    iOS: function() {  
        return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true false;  
    },  
    Windows: function() {  
        return navigator.userAgent.match(/IEMobile/i) ? true false;  
    },  
    any: function() {  
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());  
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-01-14
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-09-16
  • 2022-01-13
相关资源
相似解决方案