js判断是pc还是移动端


【js判断是pc还是移动端】1、pc端写 (如果是移动端跳走)
!function(){ function params(u, p){ var m = new RegExp("(?:&|/?)"+p+"=([^&$]+)").exec(u); return m ? m[1] : ''; } if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == true && params(location.search, "from") != "mobile"){ location.href = 'http://m.XXX.com'; } }();

2、移动端写 (如果打开是pc跳走)
!function(){ if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == false){ location.href = 'http://XXX.com'; } }();

    推荐阅读