zoukankan      html  css  js  c++  java
  • 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 });
    坚持下去就能成功
  • 相关阅读:
    windows 1061
    Golang 编程思维和工程实战
    Apache Tomcat jar Catalina
    MySQL Client/Server Protocol mysql协议
    蚂蚁集团万级规模 k8s 集群 etcd 高可用建设之路
    实习生系列之找实习的途径
    Yahoo!网站性能最佳体验的34条黄金守则
    onselectstart="return false"无法复制文字
    VS2008开发环境中容易遇到的3个问题之解决办法
    实践与交流:“三保险”为世界顶级安全防范软件ESET Nod32 4.0的正常使用“保驾护航”
  • 原文地址:https://www.cnblogs.com/suoking/p/4949132.html
Copyright © 2011-2022 走看看