jquery判断移动设备代码片段;pc、iphone、安卓

 1 $(document).ready(function () {
 2 /*  判断设备*/
 3     var browser={
 4         versions:function(){
 5             var u = navigator.userAgent, app = navigator.appVersion;
 6             return {
 7                 trident: u.indexOf('Trident') > -1, //IE内核
 8                 presto: u.indexOf('Presto') > -1, //opera内核
 9                 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
10                 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
11                 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
12                 ios: !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
13                 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
14                 iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
15                 iPad: u.indexOf('iPad') > -1, //是否iPad
16                 webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
17                 weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
18                 qq: u.match(/sQQ/i) == " qq" //是否QQ
19 
20             };
21         }(),
22         language:(navigator.browserLanguage || navigator.language).toLowerCase()
23     }
24     if (window.orientation == 0 || window.orientation == 180 || window.orientation == 90 || window.orientation == -90) {
25         if (window.orientation == 0 || window.orientation == 180) {
26             $("body").attr("class", "portrait");
27             orientation = 'portrait';
28             if(browser.versions.android||browser.versions.iPhone||browser.versions.iPad){ window.location.href = "mobile.html";}else{
29 
30             }
31 
32             return false;
33         }
34 
35     }
36     $(window).bind( 'orientationchange', function(e){
37         if (window.orientation == 0 || window.orientation == 180 || window.orientation == 90 || window.orientation == -90) {
38             if (window.orientation == 0 || window.orientation == 180) {
39                 $("body").attr("class", "portrait");
40                 orientation = 'portrait';
41                 if(browser.versions.android||browser.versions.iPhone||browser.versions.iPad){ window.location.href = "mobile.html";}else{
42 
43                 }
44 
45                 return false;
46             }
47 
48   i      }
49     });
50 
51 
52 
53 
54 });
坚持下去就能成功
原文地址:https://www.cnblogs.com/suoking/p/4949132.html