Key points: 1, the browser version of the judgment; 2, modify style sheet path
The 2nd is also commonly used in real-time modify the page template, forum style occasions, is actually modifying the style sheet path to load different style sheets.
Code:
Copy Code code as follows:
<script type= "Text/javascript" >
var browser=navigator.appname
var b_version=navigator.appversion
var version=b_version.split (";");
try{//code is only valid for IE browser, in order to avoid the error in other browsers, you can use the try{code body}catch (ERR) {code Body} to eliminate the error
var trim_version=version[1].replace (/[]/g, "");
if (browser== "Microsoft Internet Explorer" && trim_version== "MSIE7.0")
{
Replace "Your-stylesheet-url" with the path of the style sheet Chengxiang loaded in IE7
Document.stylesheets[0].href= "Your-stylesheet-url"; Key points for modifying style sheet paths: document.stylesheets[0].href
}
else if (browser== "Microsoft Internet Explorer" && trim_version== "MSIE6.0")
{
Replace "Your-another-stylesheet-url" with the path of the style sheet Chengxiang loaded in IE6
Document.stylesheets[0].href= "Your-another-stylesheet-url";
}
}
catch (Err) {//Catch error without any processing can also
}
</script>
Practical JS to determine browser type and version
Code:
Copy Code code as follows:
<title> Practical JS judgment Browser type and version </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script language= "JavaScript" >
var imyeah={};
var ua=navigator.useragent.tolowercase ();
var s;
(S=ua.match (/msie) ([\d.] +)/)) ? IMYEAH.IE=S[1]:
(S=ua.match (/firefox\/) ([\d.] +)/)) ? IMYEAH.FIREFOX=S[1]:
(S=ua.match (/chrome\/) ([\d.] +)/)) ? IMYEAH.CHROME=S[1]:
(S=ua.match (/opera.) ( [\d.] +)/)) ? IMYEAH.OPERA=S[1]:
(S=ua.match (/version\/) ([\d.] +). *safari/)? IMYEAH.SAFARI=S[1]: 0;
The following tests
if (imyeah.ie) document.write (' ie: ' +imyeah.ie);
if (Imyeah.firefox) document.write (' Firefox: ' +imyeah.firefox);
if (imyeah.chrome) document.write (' Chrome: ' +imyeah.chrome);
if (Imyeah.opera) document.write (' Opera: ' +imyeah.opera);
if (Imyeah.safari) document.write (' Safari: ' +imyeah.safari);
</script>
<body>
</body>
This code is very short, but it's very useful to be able to accurately determine ie, FF, Chrome, Opera, Safari browsers, and their versions.