We can easily identify the name of the browser, with the help of "JS navigator".Here we have used the "window.navigator" object that contains information about the visitor's browser.We can write "window.navigator" object without the "window" prefix
<html>
<head>
<p>
<title>Identify Browser</title> <br>
</p>
</head>
<body>
<div>
<div id="txt"></div>
<div>
<p style=" float:left; margin-left:10px; padding-top:50px;">
<strong><u>Your Browser Information:</u></strong>
<br><br><br>
<b>Browser Name : </b><span id="brwname"></span><br>
<b>Browser Full Version : </b><span id="brwvrs"></span><br>
<b>Browser Major Version: </b><span id="Mbrwvrs"></span><br>
<b>Navigator Appname : </b><span id="fullbrwvrs"></span><br>
<b>Navigator UserAgent : </b><span id="Nuseragnt"></span>
</p>
</div>
<script>
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}
var first = document.getElementById('brwname').innerHTML=browserName;
var second = document.getElementById('brwvrs').innerHTML=fullVersion;
var third = document.getElementById('Mbrwvrs').innerHTML=majorVersion;
var fourth = document.getElementById('fullbrwvrs').innerHTML=navigator.appName;
var fifth = document.getElementById('Nuseragnt').innerHTML=navigator.userAgent;
var info = [first,second,third,fourth,fifth];
alert(info);
</script>
</div>
</body>
</html>
0 Comment(s)