JS gets browser information and provides friendly prompts to avoid compatibility issues. js friendly prompts
Recently I am working on webform. browser compatibility is a problem. Here I have collected some information about obtaining browser information. When I use it for some users, I am prompted that the browser version is too low to use the upgraded version. this will save us a lot of time and effort for debugging compatibility. that's what I think ~
-
Detect browsers and versions
-
Use JavaScript to check the name and version of a visitor's browser.
-
Code Section:
-
<Html>
<Body>
<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 ("<br/> ")
Document. write ("browser version:" + version)
</Script>
</Body>
</Html>
-
Result:
-
Browser name: Netscape
Browser version: 5
-
Detect more information about the browser
-
Use JavaScript to detect more information about the visitor's browser.
-
Code Section:
-
<Html>
<Body>
<Script type = "text/javascript">
Document. write ("<p> Browser :")
Document. write (navigator. appName + "</p> ")
Document. write ("<p> browser version :")
Document. write (navigator. appVersion + "</p> ")
Document. write ("<p> Code :")
Document. write (navigator. appCodeName + "</p> ")
Document. write ("<p> platform :")
Document. write (navigator. platform + "</p> ")
Document. write ("<p> Cookies enabled :")
Document. write (navigator. cookieEnabled + "</p> ")
Document. write ("<p> browser user proxy header :")
Document. write (navigator. userAgent + "</p> ")
</Script>
</Body>
</Html>
-
Result:
-
Browser: Netscape
Browser version: 5.0 (Windows)
Code: Mozilla
Platform: Win32
Cookies enabled: true
Browser user proxy header: Mozilla/5.0 (Windows NT 6.1; rv: 20.0) Gecko/20100101 Firefox/20.0
-
Detects all browser Information
-
Use JavaScript to detect all information about the visitor's browser.
-
Code Section:
-
<Html>
<Body>
<Script type = "text/javascript">
Var x = navigator;
Document. write ("CodeName =" + x. appCodeName );
Document. write ("<br/> ");
Document. write ("MinorVersion =" + x. appMinorVersion );
Document. write ("<br/> ");
Document. write ("Name =" + x. appName );
Document. write ("<br/> ");
Document. write ("Version =" + x. appVersion );
Document. write ("<br/> ");
Document. write ("CookieEnabled =" + x. cookieEnabled );
Document. write ("<br/> ");
Document. write ("CPUClass =" + x. cpuClass );
Document. write ("<br/> ");
Document. write ("OnLine =" + x. onLine );
Document. write ("<br/> ");
Document. write ("Platform =" + x. platform );
Document. write ("<br/> ");
Document. write ("UA =" + x. userAgent );
Document. write ("<br/> ");
Document. write ("BrowserLanguage =" + x. browserLanguage );
Document. write ("<br/> ");
Document. write ("SystemLanguage =" + x. systemLanguage );
Document. write ("<br/> ");
Document. write ("UserLanguage =" + x. userLanguage );
</Script>
</Body>
</Html>
-
Result:
-
CodeName = Mozilla
MinorVersion = undefined
Name = Netscape
Version = 5.0 (Windows)
CookieEnabled = true
CPUClass = undefined
OnLine = true
Platform = Win32
UA = Mozilla/5.0 (Windows NT 6.1; rv: 20.0) Gecko/20100101 Firefox/20.0
BrowserLanguage = undefined
SystemLanguage = undefined
UserLanguage = undefined
-
Remind users based on browser type
-
Use JavaScript to check the browser name and version of the visitor, and then generate a warning box for different content based on the information.
-
Code Section:
-
<Html>
<Head>
<Script type = "text/javascript">
Function detectBrowser ()
{
Var browser = navigator. appName
Var B _version = navigator. appVersion
Var version = parseFloat (B _version)
If (browser = "Netscape" | browser = "Microsoft Internet Explorer") & (version> = 4 ))
{Alert ("your browser is advanced! ")}
Else
{Alert ("it's time to upgrade your browser! ")}
}
</Script>
</Head>
<Body onload = "detectBrowser ()">
</Body>
</Html>
-
Result:
-
When the browser is running, it will pop up in a pop-up window.
-
For example, I used Firefox.
-
Note that the version numbers of JavaScript in IE6, IE5, and IE4 are the same.
-
Note: Darren