Web Development Browser (ii)----jquery or JS to determine the browser kernel version number and whether to support the box model

Source: Internet
Author: User



1,jquery or JS to determine the browser kernel version number and whether to support the box model



JQuery, starting with version 1.9, removed $.browser and $.browser.version and replaced it with $.support. In the updated version 2.0, IE 6/7/8 will no longer be supported. Later, if the user needs to support IE 6/7/8, only jQuery 1.9 can be used. later, if the user needs to support IE 6/7/8, only jQuery 1.9 and below can be used. If you want to fully support IE, and mix jQuery 1.9 and below and 2.0 and later, the official solution is to use only IE-recognized conditional expressions:


<!--[if Lt IE 9]><script src= ' jquery-1.9.0.js ' </script><! [endif]--><!--[if GTE IE 9]><script src= ' jquery-2.0.0.js ' </script><! [endif]-->





Jquery version 1.4.2 determine the browser type and version and whether or not to support the box model (mainly IE, other browser problems are relatively small)


$ (function ()  {            var strtmp  =  "Your browser name is:";            if  ($. Browser.msie)  { //ie Browser                  strTmp +=  "IE";             }            else  if ($. Browser.mozilla)  { //Firefox related browser                  strTmp +=  "Mozilla firefox";             }else  if ($.browser.chrome)  { //Google related browser (i test not recognized)                  strTmp +=  " Chrome ";            }else if ($.browser.safari)  //chrome,opera,are judged for this, { strtmp += "Safari";  } else if ($.browser.opera)  { strtmp + = "Opera";  } else { strtmp+= "Unknown"; }             strTmp +=  "  Version number is:"  //get version number                     + $.browser.version;   strTmp +=  "  Box model is:" if  ($.support.boxmodel)  { //is a box model                  strTmp +=  "box model";             }             else { //is IE box model                  strtmp +=  "IE box model";             }            $ ("#divTip"). HTML (STRTMP) ;         })





Whether the above judgments support the box model when I test all is the IE box model, it is said that the following code will become a model,



I'm sorry I didn't change my test results.


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">





Jquery1.9 Version above judge whether it is ie6-8


if (!$.support.leadingwhitespace) {}





js Judging browser type


Function getos ()  {     var OsObject =  "";     if (Navigator.userAgent.indexOf ("MSIE") >0)  {          return  "MSIE";     }    else if (isfirefox= Navigator.userAgent.indexOf ("Firefox") >0) {         return   "Firefox";     }    else if (ismozilla= Navigator.userAgent.indexOf ("Opera") >0) { //This is also judged as chrome         return  "Opera";     }    else if (isfirefox= Navigator.userAgent.indexOf ("Chrome") >0) {         return  "Chrome";     }    else if (Issafari=navigator.useragent.indexof (" Safari ") >0)  {         return  "Safari";     }     else if (isCamino= Navigator.userAgent.indexOf ("Camino") >0) {         return  "Camino";     }    else if (Ismozilla=navigator.useragent.indexof (" gecko/") >0) {         return " Gecko ";     }   }  alert ("Your browser type is:" +getos ());





The above is a little bit better than jquery, at least to identify chrome, and below this is similar to the above, is also more commonly used


$.browser.mozilla =/firefox/.test (Navigator.userAgent.toLowerCase ()); $.browser.webkit =/webkit/.test ( Navigator.userAgent.toLowerCase ()); $.browser.opera =/opera/.test (Navigator.userAgent.toLowerCase ()); $. Browser.msie =/msie/.test (Navigator.userAgent.toLowerCase ()), Var str= "", str+= "Firefox" +$.browser.mozilla+ "<br /> "str+=" WebKit "+$.browser.webkit+" <br/> "str+=" opera "+$.browser.opera+" <br/> "str+=" MSIE "+ $.browser.msie+ "<br/>"; $ ("#divTip"). html (str);







Web Development Browser (ii)----jquery or JS to determine the browser kernel version number and whether the box model is supported


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.