<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<TITLE>CSS Tutorial JS judge browser type and browser version </title>
<script type= "text/web Effects" >
var sys = {};
var ua = navigator.userAgent.toLowerCase ();
if (Window.activexobject)
sys.ie = Ua.match (/msie ([D.] +)/) [1]
else if (document.getboxobjectfor)
Sys.firefox = Ua.match (/firefox/([D.] +)/) [1]
else if (window.messageevent &&!document.getboxobjectfor)
Sys.chrome = Ua.match (/chrome/([D.] +)/) [1]
else if (Window.opera)
Sys.opera = Ua.match (/opera. ( [D.] +)/) [1]
else if (window.opendatabase)
Sys.safari = Ua.match (/version/([D.] +)/) [1];
The following tests
if (sys.ie) document.write (' ie: ' +sys.ie);
if (Sys.firefox) document.write (' Firefox: ' +sys.firefox);
if (sys.chrome) document.write (' Chrome: ' +sys.chrome);
if (Sys.opera) document.write (' Opera: ' +sys.opera);
if (Sys.safari) document.write (' Safari: ' +sys.safari);
</script>
<body>
Ie
Only IE supports the creation of ActiveX controls, so she has something that other browsers do not have, that is, the ActiveXObject function. As long as you judge the Window object exists ActiveXObject function, you can clearly determine the current browser is ie. The typical useragent of IE versions are as follows:
mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)
mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)
mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
mozilla/4.0 (compatible; MSIE 5.0; Windows NT)
Where the version number is the number after the MSIE.
Firefox
The DOM elements in Firefox have a getboxobjectfor function to get the position and size of the DOM element (ie corresponds to the getboundingclientrect function). This is unique to Firefox, judge it can know is the current browser is Firefox. Firefox several versions of the useragent are roughly as follows:
mozilla/5.0 (Windows; u; Windows NT 5.2) gecko/2008070208 firefox/3.0.1
mozilla/5.0 (Windows; u; Windows NT 5.1) gecko/20070309 firefox/2.0.0.3
mozilla/5.0 (Windows; u; Windows NT 5.1) gecko/20070803 firefox/1.5.0.12
Where the version number is the number after Firefox.
Opera
Opera offers a special browser flag, which is the Window.opera property. Opera's typical useragent is as follows:
opera/9.27 (Windows NT 5.2; u; zh-cn)
opera/8.0 (Macintosh; PPC Mac OS X; u; en)
mozilla/5.0 (Macintosh; PPC Mac OS X; u; en) Opera 8.0
Among them, the version number is close to opera's number.
Safari
Safari browser has a opendatabase function that is not available in other browsers and can be used as a marker for safari. Safari's typical useragent is as follows:
mozilla/5.0 (Windows; Windows NT 5.2) applewebkit/525.13 (khtml, like Gecko) version/3.1 safari/525.13
mozilla/5.0 (iphone; u; CPU like Mac OS X) applewebkit/420.1 (khtml, like Gecko) version/3.0 Mobile/4a93
The version number is the number after version.
Chrome
Chrome has a messageevent function, but Firefox does. However, the good news is that Chrome does not have Firefox's getboxobjectfor function, which can be used to accurately determine the Chrome browser. At present, the useragent of Chrome is:
mozilla/5.0 (Windows; Windows NT 5.2) applewebkit/525.13 (khtml, like Gecko) chrome/0.2.149.27 safari/525.13
</body>
JavaScript determines browser version
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>js Judgment Browser </title>
<body>
<!--to determine the visitor's browser (type) and version-->
<script type= "Text/javascript" >
var browser=navigator.appname
var b_version=navigator.appversion
var version=parsefloat (b_version)
document.write ("Browser name:" + browser)
document.write ("
")
document.write ("browser version:" + version)
</script>
Other information
<script type= "Text/javascript" >
document.write ("Browser:")
document.write (Navigator.appname + "")
document.write ("Browserversion:")
document.write (navigator.appversion + "")
document.write ("Code:")
document.write (Navigator.appcodename + "")
document.write ("Platform:")
document.write (Navigator.platform + "")
document.write ("Cookies enabled:")
document.write (navigator.cookieenabled + "")
document.write ("Browser ' s user Agent header:")
document.write (navigator.useragent + "")
</script>
CSS to determine user browser version information
<!--[If ie]>
<!--[if IE 5]>
<! [endif]-->
<!--[if IE 5.0]>
<! [endif]-->
<!--[if IE 5.5]>
<! [endif]-->
<!--[if IE 6]>
<! [endif]-->
<!--[if IE 7]>
<! [endif]-->
<! [endif]-->