We help IT Professionals succeed at work.

"navigator.appVersion" doesn't seem to work in IE6

raives
raives asked
on
Medium Priority
228 Views
Last Modified: 2009-07-29
I have been trying to use the following check in my JS code:

IE6 = (parseInt(navigator.appVersion) >=6);

This doesn't work correctly. Using "if (IE6) [...]" doesn't differentiate the IE 6 from earlier versions (ie the condition is never true). If I check the version using

  document.write(navigator.appVersion);

I get the following:

  4.0 (compatible; MSIE 6.0; Windows 98)

I'd like to direct IE6+ users to a different page than the users of earlier versions of the IE. All help would be greatly appreciated.

I've copied most of the relevant code below.

Vesa

IE6 = (parseInt(navigator.appVersion) >=6);
[...]
function select_page(){
      if (IE6){     //THIS IS NEVER TRUE
      window.open("../englishIE6/entrance.html","","status=yes,toolbar=yes,location=yes,width=800,height=590,resizable=yes,scrollbars=yes");
   }
      else {
      window.open("entrance.html","","status=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes");
document.write(navigator.appVersion);
   }


Comment
Watch Question

Commented:
Try using:

IE6 = (navigator.appVersion.indexOf("MSIE 6.0") > -1);


:o)

Ant

Commented:
Take a look at:
http://www.webreference.com/tools/browser/javascript.html

Kind regards,

nmeat

Author

Commented:
Thanks, a.marsh. But will that work with later versions of IE too (e.g. version 6.1)? Sorry I'm not very familiar with JavaScript...

Vesa

Commented:
No, but making this adjustment, it should do:

IE6 = (navigator.appVersion.indexOf("MSIE 6") > -1);


You can't really plan for future browsers - who knows what will change!

That's one of the major drawbacks of coding pages where you need to do browse dependency checking.

:o\

Ant

Commented:
Any feedback on this raives?

:o)

Ant

Author

Commented:
Sorry, I had somehow missed your 2nd last comment. However, the solution offered therein seems to be identical to the one in your earlier comment:

You wrote earlier:

 Try using:
 IE6 = (navigator.appVersion.indexOf("MSIE 6.0") > -1);

To which I replied:

 Thanks, a.marsh. But will that work with later versions of IE too (e.g. version 6.1)?

To which you replied:

 No, but making this adjustment, it should do:
 IE6 = (navigator.appVersion.indexOf("MSIE 6.0") > -1);

(As you see, the "adjusted" version is similar to your original proposal.) Anyway, I assume this is what I must do with. Could you just explain what the greater than -1 part means in concrete terms? I'd like to know the logic behind whatever I use. :)

Vesa
Commented:
It was not the same - I removed the ".0" part if you look closely.

:o)

Basically the browser looks for the string "MSIE 6" and if it doesn't find it then it returns a value of -1 but if it does then it returns a value greater than -1 usually a 1.

:o)

Ant

Author

Commented:
Ok, sorry. And thanks for the explanation.

Vesa

Commented:
My pleasure. :o)

Thanks for the A!

Ant