Click to See Complete Forum and Search --> : checking for browser type and version
sidownes
12-06-2002, 08:44 AM
I'm trying to check the version number of the browser to detect whether it is netscape version 6 or above:
var g_ns6 = (navigator.userAgent.indexOf("Netscape6")>0);
var g_ie5 = ((navigator.userAgent.indexOf("MSIE 5")>0)||(navigator.userAgent.indexOf("MSIE 6")>0));
Please could someone give me a pointer int he right direction.
Cheers
Zach Elfers
12-06-2002, 09:02 AM
Here how to do a browser check:
function checkBrowser() {
if (navigator.appName == "MSIE") {
self.location.href = "somepage.html";
}
else {
self.location.href = "otherpage.html";
}
}
That will work for figuring out the browser. I'm not sure how to check for the version, but I think it might go like this:
function checkBrowserVersion() {
if (navigator.appName == "MSIE" && navigator.appVersion >= 5) {
self.location.href = "msie5.html";
}
else {
self.location.href = "otherpage.html";
}
}
I think that will work BUT I am not sure.:)
sidownes
12-06-2002, 10:08 AM
I'm having to specifically check that the Netscape browers is version 6 or above. Any ideas?
Zach Elfers
12-06-2002, 10:38 AM
Change MSIE to Netscape and 5 to 6.
Vladdy
12-06-2002, 11:31 AM
check for gecko, not the NS6.0+
function testBrowser()
{ if(!navigator)
{ browser = 'nc';
return;
}
if(navigator.userAgent.indexOf('Opera')>0)
{ browser = 'op';
return;
}
if(navigator.appName == 'Netscape')
{ version = parseFloat(navigator.appVersion);
if(version < 5.0)
{ browser = 'ns';
return;
}
}
if(navigator.appName == 'Microsoft Internet Explorer')
{ browser='ie';
str = navigator.appVersion;
str = str.substring(str.indexOf('MSIE')+4,str.length);
version = parseFloat(str);
return;
}
if(navigator.product)
{ if(navigator.product == 'Gecko')
{ browser = 'gecko';
releasedate = navigator.productSub;
version = parseFloat(releasedate.replace(/(\d{4})(\d{2})(\d{2})/,'$1.$2$3'));
}
else
{ browser = '??';
}
return;
}
browser = '??';
return;
}
gil davis
12-06-2002, 03:53 PM
http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html