Key points: 1. Determine the browser version; 2. Modify the style sheet path
The second point is often used when you modify webpage templates and Forum styles in real time. In fact, you can modify the style sheet path to load different style sheets.
Code:
Copy codeThe Code is as follows: <script type = "text/javascript">
Var browser = navigator. appName
Var B _version = navigator. appVersion
Var version = B _version.split (";");
Try {// The code is only valid for IE browsers. To avoid errors reported in other browsers, try {code body} catch (err) {code body} can be used to eliminate errors.
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 table to be loaded in ie7
Document. styleSheets [0]. href = "your-stylesheet-url"; // you can modify the path of the style sheet at the key points: 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 to be loaded in ie6
Document. styleSheets [0]. href = "your-another-stylesheet-url ";
}
}
Catch (err) {// catch errors without any processing
}
</Script>
Practical js judgment of browser types and versions
Code:Copy codeThe Code is as follows: <Head>
<Title> practical js judgment of browser types and versions </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;
// Perform 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>
</Head>
<Body>
</Body>
</Html>
This code is very short, but it is very practical to accurately judge ie, FF, Chrome, Opera, Safari browser and its version.