Dateigrösse: 9.57 kb
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 6 <title>NavigatorCheckjQuery</title> 7 8 <style type="text/css"> 9 body { font:bold 14pt verdana,arial,sans-serif; padding:10pt; margin:20pt; color:#000; background:#fff; } 10 #bwtype { font:bold 30pt arial,verdana,sans-serif; margin:20pt 0; padding:3pt 5pt; background:#fff; border:1pt solid #656565; border-radius: 10px; box-shadow: .3em .3em .5em rgba(0, 0, 0, .8); width:90%; } 11 h4 { margin: 12pt; } 12 a.jquery_bw { position:absolute; top:33%; left:30pt; color:#cc0033; padding:2px 3px; margin-top:20pt; text-decoration:none; letter-spacing:2px; text-shadow:0 0 2pt #333; } 13 a.jquery_bw:hover { color:black; } 14 </style> 15 <!-- 16 <script src="https://code.jquery.com/jquery-3.0.0.js"></script> 17 <script src="https://code.jquery.com/jquery-migrate-3.0.0.js"></script> 18 --> 19 <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 20 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 21 <script src="jQuery/jquery-browser-plugin/dist/jquery.browser.js"></script> 22 23 <script type="text/javascript"> 24 25 (function (factory) { 26 if (typeof define === 'function' && define.amd) { 27 // AMD. Register as an anonymous module 28 define(['jquery'], function ($) { 29 return factory($); 30 }); 31 } else if (typeof module === 'object' && typeof module.exports === 'object') { 32 // Node-like environment 33 module.exports = factory(require('jquery')); 34 } else { 35 // Browser globals 36 factory(window.jQuery); 37 } 38 }(function(jQuery) { 39 "use strict"; 40 function uaMatch( ua ) { 41 // If an UA is not provided, default to the current browser UA. 42 if ( ua === undefined ) { 43 ua = window.navigator.userAgent; 44 } 45 ua = ua.toLowerCase(); 46 47 var match = /(edge)\/([\w.]+)/.exec( ua ) || 48 /(opr)[\/]([\w.]+)/.exec( ua ) || 49 /(chrome)[ \/]([\w.]+)/.exec( ua ) || 50 /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || 51 /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) || 52 /(webkit)[ \/]([\w.]+)/.exec( ua ) || 53 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || 54 /(msie) ([\w.]+)/.exec( ua ) || 55 ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) || 56 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || 57 []; 58 59 var platform_match = 60 /(ipad)/.exec( ua ) || 61 /(ipod)/.exec( ua ) || 62 /(iphone)/.exec( ua ) || 63 /(kindle)/.exec( ua ) || 64 /(silk)/.exec( ua ) || 65 /(android)/.exec( ua ) || 66 /(windows phone)/.exec( ua ) || 67 /(win)/.exec( ua ) || 68 /(mac)/.exec( ua ) || 69 /(linux)/.exec( ua ) || 70 /(cros)/.exec( ua ) || 71 /(playbook)/.exec( ua ) || 72 /(bb)/.exec( ua ) || 73 /(blackberry)/.exec( ua ) || 74 []; 75 76 var browser = {}, 77 matched = { 78 browser: match[ 5 ] || match[ 3 ] || match[ 1 ] || "", 79 version: match[ 2 ] || match[ 4 ] || "0", 80 versionNumber: match[ 4 ] || match[ 2 ] || "0", 81 platform: platform_match[ 0 ] || "" 82 }; 83 84 if ( matched.browser ) { 85 browser[ matched.browser ] = true; 86 browser.version = matched.version; 87 browser.versionNumber = parseInt(matched.versionNumber, 10); 88 } 89 90 if ( matched.platform ) { 91 browser[ matched.platform ] = true; 92 } 93 94 // These are all considered mobile platforms, meaning they run a mobile browser 95 if ( browser.android || browser.bb || browser.blackberry || browser.ipad || browser.iphone || 96 browser.ipod || browser.kindle || browser.playbook || browser.silk || browser[ "windows phone" ]) { 97 browser.mobile = true; 98 } 99 100 // These are all considered desktop platforms, meaning they run a desktop browser 101 if ( browser.cros || browser.mac || browser.linux || browser.win ) { 102 browser.desktop = true; 103 } 104 105 // Chrome, Opera 15+ and Safari are webkit based browsers 106 if ( browser.chrome || browser.opr || browser.safari ) { 107 browser.webkit = true; 108 } 109 110 // IE11 has a new token so we will assign it msie to avoid breaking changes 111 // IE12 disguises itself as Chrome, but adds a new Edge token. 112 if ( browser.rv || browser.edge ) { 113 var ie = "msie"; 114 115 matched.browser = ie; 116 browser[ie] = true; 117 } 118 119 // Blackberry browsers are marked as Safari on BlackBerry 120 if ( browser.safari && browser.blackberry ) { 121 var blackberry = "blackberry"; 122 123 matched.browser = blackberry; 124 browser[blackberry] = true; 125 } 126 127 // Playbook browsers are marked as Safari on Playbook 128 if ( browser.safari && browser.playbook ) { 129 var playbook = "playbook"; 130 131 matched.browser = playbook; 132 browser[playbook] = true; 133 } 134 135 // BB10 is a newer OS version of BlackBerry 136 if ( browser.bb ) { 137 var bb = "blackberry"; 138 139 matched.browser = bb; 140 browser[bb] = true; 141 } 142 143 // Opera 15+ are identified as opr 144 if ( browser.opr ) { 145 var opera = "opera"; 146 147 matched.browser = opera; 148 browser[opera] = true; 149 } 150 151 // Stock Android browsers are marked as Safari on Android. 152 if ( browser.safari && browser.android ) { 153 var android = "android"; 154 155 matched.browser = android; 156 browser[android] = true; 157 } 158 159 // Kindle browsers are marked as Safari on Kindle 160 if ( browser.safari && browser.kindle ) { 161 var kindle = "kindle"; 162 163 matched.browser = kindle; 164 browser[kindle] = true; 165 } 166 167 // Kindle Silk browsers are marked as Safari on Kindle 168 if ( browser.safari && browser.silk ) { 169 var silk = "silk"; 170 171 matched.browser = silk; 172 browser[silk] = true; 173 } 174 175 // Assign the name and platform variable 176 browser.name = matched.browser; 177 browser.platform = matched.platform; 178 return browser; 179 } 180 181 // Run the matching process, also assign the function to the returned object 182 // for manual, jQuery-free use if desired 183 window.jQBrowser = uaMatch( window.navigator.userAgent ); 184 window.jQBrowser.uaMatch = uaMatch; 185 186 // Only assign to jQuery.browser if jQuery is loaded 187 if ( jQuery ) { 188 jQuery.browser = window.jQBrowser; 189 } 190 191 return window.jQBrowser; 192 })); 193 194 195 function getBack() 196 { 197 if(jQuery.browser.mobile) 198 { 199 document.getElementById('self').innerHTML = 'Mobile'; 200 } 201 else if (jQuery.browser.desktop) 202 { 203 document.getElementById('self').innerHTML = 'Desktop'; 204 } 205 else { 206 document.getElementById('self').innerHTML = 'undefined'; 207 } 208 } 209 210 /***********************************************************************/ 211 $(document).ready(function() { 212 // 213 var div = document.getElementById('bwtype'); 214 div.style.fontSize = "30pt"; 215 div.style.background = "#b00"; 216 div.style.color = "#fff"; 217 div.innerHTML = ''; 218 // If the browser type is Mozilla it`s Firefox 219 if ($.browser.mozilla && $.browser.version >= "1.8") 220 { 221 div.innerHTML += '<h4>You are using Firefox v.'+$.browser.versionNumber+'</h4>'; 222 } 223 // If the web browser type is Opera 224 if( $.browser.opera ) 225 { 226 div.innerHTML += '<h4>You are using Opera v.'+$.browser.versionNumber+'</h4>'; 227 } 228 // If the web browser type is Safari 229 if( $.browser.safari ) 230 { 231 div.innerHTML += '<h4>You are using Safari v.'+$.browser.versionNumber+'</h4>'; 232 } 233 // If the web browser type is Chrome 234 if( $.browser.chrome ) 235 { 236 div.innerHTML += '<h4>You are using Chrome v.'+$.browser.versionNumber+'</h4>'; 237 } 238 // If the web browser type is Internet Explorer 239 if ($.browser.msie && $.browser.version <= 6) 240 { 241 if(document.all && !window.XMLHttpRequest) { 242 document.write('You are using IE 6'); 243 } 244 else if(document.all && !document.compatMode) { 245 document.write('You are using IE 5.x'); 246 } 247 else { 248 document.write('You are using MSIE'); 249 } 250 } 251 //If the web browser type is Internet Explorer 6 and above 252 if ($.browser.msie && $.browser.version > 6) 253 { 254 if(document.all) { 255 document.write('You are using IE 10+'); 256 } 257 else if(document.all && !window.atob) { 258 document.write('You are using IE 9'); 259 } 260 else if(document.all && !document.addEventListener) { 261 document.write('You are using IE 8'); 262 } 263 else if(document.all && !document.querySelector) { 264 document.write('You are using IE 7'); 265 } 266 else if($.browser.rv) { 267 div.innerHTML += '<h4>You are using IE v.'+$.browser.versionNumber+'</h4>'; 268 } 269 else if($.browser.edge) { 270 div.innerHTML += '<h4>You are using IE v.'+$.browser.versionNumber+'</h4>'; 271 } 272 else { 273 document.write('You are using MSIE'); 274 } 275 } 276 }); 277 278 /* 279 IE 10 or older - document.all <br/> 280 IE 9 or older - document.all && !window.atob <br/> 281 IE 8 or older - document.all && !document.addEventListener <br/> 282 IE 7 or older - document.all && !document.querySelector <br/> 283 IE 6 or older - document.all && !window.XMLHttpRequest <br/> 284 IE 5.x - document.all && !document.compatMode <br/> 285 */ 286 </script> 287 288 </head> 289 290 <body> 291 292 <h2 id="self" onclick="getBack();">Desktop or Mobile Device? onClick here:</h2> 293 294 <div id="bwtype"></div> 295 296 <a class="jquery_bw" href="http://www.michaelster.ch/jsTestFolder/jQuery/jquery-browser-plugin/test/">jQuery Browser Check: see more examples here ...</a> 297 298 </body> 299 </html> 300