Get Browser Name and Version
Hi Friends, I would like to explain how to get the browser name and version using JavaScript, this article is very useful for cross browser compatibility. I have facing a problem, the pop-up is working in IE but not working in Mac Firefox, so I wrote code based on browsers.
Step 1:
First add this browsercheck.js into your application and add the script into your html or asp file.
Step 2:add this code in html body.
That’s it. I hope you like this article.
Final Words
Click here to download this code
Step 1:
First add this browsercheck.js into your application and add the script into your html or asp file.
var isNav = false
var isIE = false
var isChrome = false
// This function returns the browser Name and Version of the browser
// Based on this function you can manipulates the browser compatibility also
function getBroserVersion() {
var agmt = navigator.userAgent.toLowerCase()
var version = 0
if (agmt.indexOf('msie') != -1) {
isIE = true
if (agmt.indexOf('msie 3.') != -1)
version = 3
else if (agmt.indexOf('msie 4.') != -1)
version = 4
else if (agmt.indexOf('msie 5.5') != -1)
version = 5.5
else if (agmt.indexOf('msie 5.') != -1)
version = 5
else if (agmt.indexOf('msie 6.') != -1)
version = 6
else if (agmt.indexOf('msie 7.') != -1)
version = 7
else if (agmt.indexOf('msie 8.') != -1)
version = 8
else if (agmt.indexOf('msie 9.') != -1)
version = 9
}
else if (agmt.indexOf('firefox') != -1) {
isNav = true
if (agmt.indexOf('mozilla/2.0') != -1)
version = 2
else if (agmt.indexOf('mozilla/3.0') != -1)
version = 3
else if (agmt.indexOf('mozilla/4.0') != -1)
version = 4
else if (agmt.indexOf('mozilla/4.5') != -1)
version = 4.5
else if (agmt.indexOf('mozilla/4.6') != -1)
version = 4.6
else if (agmt.indexOf('mozilla/4.7') != -1)
version = 4.7
else if (agmt.indexOf('mozilla/4.8') != -1)
version = 4.8
else if (agmt.indexOf('mozilla/4.9') != -1)
version = 4.9
else if (agmt.indexOf('mozilla/5.') != -1)
version = 5
else if (agmt.indexOf('mozilla/6.') != -1)
version = 6
else if (agmt.indexOf('mozilla/7.') != -1)
version = 7
else if (agmt.indexOf('mozilla/8.') != -1)
version = 8
else if (agmt.indexOf('mozilla/9.') != -1)
version = 9
}
else if (agmt.indexOf('chrome') != -1) {
isChrome = true
}
//check broser and versions
if (isNav && version) {
alert("Hi, This is Firefox and my version is " + version)
}
if (isIE && version) {
alert("Hi, This is IE and my version is "+version)
}
if (isChrome) {
alert("Hi, This is Google Chrome")
}
}
Step 2:add this code in html body.
How to get the Browser Name and Version
That’s it. I hope you like this article.
Final Words
Click here to download this code
Thank's
www.pioneerscode.com
Tags: cross browser compatibility
