js设备型号判断

判断当前页面是否是手机端开启
将此段代码放在head头部中,如果是手机端访问,就会自动跳转移动端页面

<script>var ua = window.navigator.userAgent;if (/iphone|ipad|android|linux|uc/i.test(ua)) {location = 'http://www.ceshi.com/m/';}</script>

判断当前设备是安卓端还是IOS

var u = navigator.userAgent; //http请求用户代理头
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //判断Android终端
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
console.log('是安卓:'+isAndroid)
console.log('是IOS:'+isIOS)
发布了76 篇原创文章 · 获赞 144 · 访问量 2926

猜你喜欢

转载自blog.csdn.net/qq_40745143/article/details/103902455