码迷,mamicode.com
首页 > Web开发 > 详细

YJ智能框架--JS判断浏览器类型及版本

时间:2017-06-05 16:51:02      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:ora   atm   tin   anim   glob   html   theme   hone   cal   

YJ智能框架--JS判断浏览器类型及版本以下

  1     /**
  2      * 判断用的是那个浏览器,操作系统,浏览器使用的内核
  3      */
  4     (function() {
  5         var ua = navigator.userAgent || "";
  6         YJ.browser = "";
  7         if (document.recalc || document.documentMode) {
  8             YJ.browser = "ie";
  9         }
 10         if (window.XULElement || ua.match("Gecko")) {
 11             YJ.browser = "gecko";
 12         }
 13         if (window.opera) {
 14             YJ.browser = "opera";
 15             opera.setOverrideHistoryNavigationMode(‘compatible‘);
 16             history.navigationMode = ‘compatible‘;
 17         }
 18         if (ua.match("WebKit")) {
 19             YJ.browser = "webkit";
 20         }
 21         if (ua.match("Konqueror")) {
 22             YJ.browser = "konqueror";
 23         }
 24         if (YJ.browser) {
 25             YJ[YJ.browser] = true;
 26         }
 27         if (YJ.webkit) {
 28             if (ua.match("Chrome")) {
 29                 YJ.chrome = true;
 30                 var rwebkit = /(chrome)[ \/]([\w]+)/i;
 31                 var match = rwebkit.exec(ua);
 32                 YJ.chromeVersion = match[2];
 33             } else if (ua.match("Safari")) {
 34                 YJ.safari = true;
 35             }
 36         }
 37         if ("ontouchstart" in window || navigator.msMaxTouchPoints > 0) {
 38             YJ.touch = true
 39         }
 40         if (ua.match(/iPhone|iPad|iPod|Android/)) {
 41             YJ.mobile = true
 42         }
 43         if (YJ.safari && !document.evaluate) {
 44             YJ.safari2 = true;
 45         }
 46         if (ua.match("Mac OS")) {
 47             YJ.mac = true
 48         }
 49         if (!ua.match("Windows")) {
 50             YJ.unix = true;
 51         }
 52         YJ.theme = "classic";
 53         if (ua.match("Windows NT 6")) {
 54             YJ.theme = "vista";
 55         }
 56         if (ua.match("Windows NT 5.1")) {
 57             YJ.theme = "xp";
 58         }
 59         if (ua.match("Mac OS") || ua.match("Android")) {
 60             YJ.theme = "aqua";
 61         }
 62         
 63         YJ.strict = ("" + document.compatMode).match("CSS");
 64         if (YJ.safari2 || (YJ.safari && !document.compatMode && document.doctype && (document.doctype.systemId || !("" + document.doctype.publicId).match(/(Transitional|Final)/)))) {
 65             YJ.strict = true;
 66         }
 67         if (!YJ.strict) {
 68             YJ.quirks = true;
 69         }
 70         var htmlc = " yj-all";
 71         if (YJ.strict) {
 72             htmlc += " yj-strict";
 73         }
 74         if (YJ.quirks) {
 75             htmlc += " yj-quirks";
 76         }
 77         if (YJ.browser) {
 78             htmlc += " yj-" + YJ.browser;
 79         }
 80         if (YJ.safari) {
 81             htmlc += " yj-safari";
 82         }
 83         if (YJ.chrome) {
 84             htmlc += " yj-chrome";
 85         }
 86         if (YJ.touch) {
 87             htmlc += " yj-touch"
 88         }
 89         if (YJ.mobile) {
 90             htmlc += " yj-mobile"
 91         }
 92         if (YJ.unix) {
 93             htmlc += " yj-unix";
 94         }
 95         if (YJ.theme) {
 96             htmlc += " yj-" + YJ.theme;
 97         }
 98         if (YJ.theme && YJ.strict) {
 99             htmlc += " yj-" + YJ.theme + "-strict";
100         }
101         if (YJ.ie) {
102             var s = document.documentElement.currentStyle;            
103             if (ua.match("MSIE 11")) {
104                 YJ.ie11 = true;
105                 htmlc += " yj-ie11"
106             }else if (ua.match("MSIE 10")) {
107                 YJ.ie10 = true;
108                 htmlc += " yj-ie10"    
109             } else if (ua.match("MSIE 9")) {
110                 YJ.ie9 = true;
111                 htmlc += " yj-ie9"
112             } else if (s.outlineStyle) {
113                 YJ.ie8 = true;
114                 htmlc += " yj-ie8";
115             } else if (s.maxWidth) {
116                 YJ.ie7 = true;
117                 htmlc += " yj-ie7";
118             } else if (s.textOverflow) {
119                 YJ.ie6 = true;
120                 htmlc += " yj-ie6";
121             } else if (s.writingMode) {
122                 YJ.ie5 = true;
123                 htmlc += " yj-ie5";
124             }
125             YJ.ieDocVer = document.documentMode;
126             if (document.documentMode >= 11) {
127                 YJ.ms11 = true;
128                 htmlc += " yj-ms11"
129             }else if (document.documentMode == 10) {
130                 YJ.ms10 = true;
131                 htmlc += " yj-ms10"
132             } else if (document.documentMode == 9) {
133                 YJ.ms9 = true;
134                 htmlc += " yj-ms9"
135             } else if (document.documentMode == 8) {
136                 YJ.ms8 = true;
137                 htmlc += " yj-ms8";
138             } else if (document.documentMode == 7 || (YJ.ie7 && YJ.strict)) {
139                 YJ.ms7 = true;
140                 htmlc += " yj-ms7";
141             } else if (YJ.ie6 && YJ.strict) {
142                 YJ.ms6 = true;
143                 htmlc += " yj-ms6";
144             } else {
145                 YJ.ms5 = true;
146                 htmlc += " yj-ms5";
147             }
148         }
149         if (YJ.gecko) {
150             if (window.mozRequestAnimationFrame) {
151                 YJ.ff4 = true;
152                 htmlc += " yj-ff4"
153             } else if (document.elementFromPoint) {
154                 YJ.ff3 = true;
155                 htmlc += " yj-ff3";
156             } else if (window.globalStorage) {
157                 YJ.ff2 = true;
158                 htmlc += " yj-ff2";
159             } else if (window.XPCNativeWrapper) {
160                 YJ.ff15 = true;
161                 htmlc += " yj-ff15";
162             } else {
163                 YJ.ff1 = true;
164                 htmlc += " yj-ff1";
165             }
166             if (YJ.ff4 || YJ.ff3) {
167                 YJ.ff = true;
168                 htmlc += " yj-ff"
169             }
170             if (YJ.ff2 || YJ.ff15 || YJ.ff1) {
171                 YJ.ffx = true;
172                 htmlc += " yj-ffx";
173             }
174         }
175         if (YJ.ie5 || YJ.ie6) {
176             htmlc += " yj-png1 yj-" + YJ.theme + "-png1";
177         } else {
178             htmlc += " yj-png2";
179         }
180         YJ._htmlClasses = htmlc;
181         if (YJ.strict) {
182             YJ.dx = 8;
183             YJ.dy = 4;
184         } else {
185             YJ.dx = 0;
186             YJ.dy = 0;
187         }
188         if(YJ.mobile){
189             YJ.sx = 6;
190             YJ.sy = 6;
191         }else if(YJ.mac){
192             YJ.sx = 8;
193             YJ.sy = 8;
194         }else{
195             YJ.sx = 20;
196             YJ.sy = 20;
197         }
198     })();

 

YJ智能框架--JS判断浏览器类型及版本

标签:ora   atm   tin   anim   glob   html   theme   hone   cal   

原文地址:http://www.cnblogs.com/wangzhongming/p/6945459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!