JS Get browser information, give a friendship hint, avoid some compatibility issues

Source: Internet
Author: User

Recently in doing WebForm, browser compatibility is a problem, here I collected some information to obtain the browser, can be used for some users, prompted the browser version is too low, let the upgrade version.  This will save us a lot of time and effort to debug compatibility. That's what I think.

Detect browser and version
use JavaScript to detect browser names and their versions of visitors.
Code section:
<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>
Results:
Browser Name: Netscape
Browser version: 5
More information on detecting browsers
use JavaScript to detect more information about the visitor's browser.
Code section:
<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> User Agent header for browser:")
document.write (navigator.useragent + "</p>")
</script>
</body>

Results:

Browser: Netscape

Browser version: 5.0 (Windows)

Code: Mozilla

Platform: Win32

Cookies Enabled: True

User Agent header for browser: mozilla/5.0 (Windows NT 6.1; rv:20.0) gecko/20100101 firefox/20.0

Detect all of your browser's information
use JavaScript to detect all information about the visitor's browser.
Code section:
<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>
Results:
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
Alert users based on browser type
use JavaScript to detect the browser name and version of the visitor, and then generate a warning box for different content based on that information.
Code section:
<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 enough! ")}
Else
{Alert ("It's time to upgrade your browser! ")}
}
</script>
<body onload= "Detectbrowser ()" >
</body>

Results:
when the browser is running, it pops up in the form of a pop-up window.
For example, I use the Firefox browser.
One thing Bo friends should note is that JavaScript gets the same version number in IE6, IE5, and IE4.
Note: Darren

JS Get browser information, give a friendship hint, avoid some compatibility issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.