To obtain the browser version, we can not only use the server script to determine the same, but also use js to obtain the browser version information. To obtain the browser version in js, we only need to use navigator, let's take a look at the instance.
Core code
The Code is as follows: |
Copy code |
Var Sys = {}; Var ua = navigator. userAgent. toLowerCase (); Var s; Var scan; (S = ua. match (/msie ([d.] + )/))? Sys. ie = s [1]: (S = ua. match (/firefox/([d.] + )/))? Sys. firefox = s [1]: (S = ua. match (/chrome/([d.] + )/))? Sys. chrome = s [1]: (S = ua. match (/opera. ([d.] + )/))? Sys. opera = s [1]: (S = ua. match (/version/([d.] +). * safari /))? Sys. safari = s [1]: 0; // Perform the following tests: If (Sys. ie) { Scan = "your ie kernel" + Sys. ie + "Browser "; } If (Sys. firefox) { Scan = "you are using the firefox kernel" + Sys. firefox + "browser. If you have any problems, we recommend that you use IE "; } If (Sys. chrome) { Scan = "you are using the chrome kernel" + Sys. chrome + "www. bKjia. c0m browser. If you have any problems, we recommend that you use IE "; } If (Sys. opera) { Scan = "you are using the opera kernel" + Sys. opera + "browser. If you have any problems, we recommend that you use IE "; } If (Sys. safari) { Scan = "you are using the safari kernel" + Sys. safari +"BKjia. c0mBrowser. If any problem occurs, we recommend that you use IE "; } Alert (scan) |
Next, let's look at some selected instances.
Application Instance
The Code is as follows: |
Copy code |
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/5o/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> js test </title> <Script type = "text/javascript"> Function PrintVersion (){ Var msg = ""; Msg + = "browser name:" + navigator. appName + "n "; Msg + = "browser version:" + navigator. appVersion + "n "; Msg + = "browser code:" + navigator. appCodeName + "n "; Alert (msg ); } </Script> </Head> <Body> <Form name = "MyForm"> <Input type = "submit" name = "Submit" value = "click" onclick = "PrintVersion ()"/> </Form> </Body> </Html> |
Example 2
This instance is more comprehensive
The Code is as follows: |
Copy code |
<Title> JS displays details of the current browser </title> <SCRIPT> <! -- Begin Function whatBrowser (){ Document. Browser. Name. value = navigator. appName; Document. Browser. Version. value = navigator. appVersion; Document. Browser. Code. value = navigator. appCodeName; Document. Browser. Agent. value = navigator. userAgent; } // End --> </SCRIPT> <Table border> <Form name = "Browser"> <TR> <TD> name: </TD> <TD> <input type = "txt" NAME = "Name" Size = "45"> </TD> </TR> <TR> <TD> Version: </TD> <TD> <input type = "txt" NAME = "Version" Size = "45"> </TD> </TR> <TR> <TD> kernel: </TD> <TD> <input type = "txt" NAME = "Code" Size = "45"> </TD> </TR> <TR> <TD> User-Agent: </TD> <TD> <input type = "txt" NAME = "Agent" Size = "45"> </TD> </TR> </FORM> </TABLE> <Body bgcolor = "# fef4d9" onLoad = "whatBrowser ()"> </body> |