I need to be able to tell if a page is being viewed in IE 6. How can I do this in javascript while ignoring version like 7, 8, or other browsers?
+9
A:
straight from the horse's mouth (and one googling away):
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
mkoryak
2009-05-27 18:19:32
This is a good alternative approach. +1
ceejayoz
2009-05-27 18:24:02
+1: I actully used this in combination with mkoryak's answer.
Lucas McCoy
2009-05-27 18:44:18
This is a better approach - since it gives the "right" result on other browsers that use the IE6 engine and is immune to user-agent spoofing. Better yet would likely be to use feature AKA object detection instead of user agent detection - http://www.quirksmode.org/js/support.html
David Dorward
2009-05-27 20:07:49
you know, the link i provided has all of this information, about conditional comments, and feature detection, even some hacks
mkoryak
2009-05-27 20:35:18
@mkoryak: Thats why it's my accepted answer ;-)
Lucas McCoy
2009-05-27 21:48:18