getting IE version

A

Andrew Poulos

Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Andrew Poulos
 
K

Kevin Newman

Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Andrew Poulos

if (/MSIE/.test(navigator.appVersion) &&
!/Opera/.test(navigator.userAgent) ) }

var IEVersion = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1];
}


I think this will only work in IE 4.0+ though (haven't tested it on IE 3.x)

Kevin N.
 
I

Ivo

Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Anything relying on the navigator properties is by definition far from safe
or robust, as the navigator identifier strings can easily be spoofed with
the express purpose of making you think you are dealing with a different
browser. Many browsers even ship spoofed.

Try feature detection. If a feature does not exist in one version of
JScript, but does in another, testing for its availability will tell you
something the version of script, which in turn is a clue towards determining
the version of the browser.
Which browsers runs which JScript versions, and which features come with
which version, is all listed here:
<URL:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriversioninform
ation.asp >

As of Internet Explorer 5.0, there is also a native function ScriptEngine()
which gives the exact number of the JScript version in use. See
<URL:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsfctScriptEngine.
asp >
or
<URL: http://4umi.com/web/javascript/jscript.htm >

hth
Ivo
 
R

Randy Webb

Andrew Poulos said the following on 8/4/2005 9:31 AM:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

It's about as robust as taking a wild guess at what the browser is. The
navigator object is useless in trying to determine the environment, use
object detection instead.
 
R

Randy Webb

Kevin Newman said the following on 8/4/2005 11:05 AM:
Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Andrew Poulos


if (/MSIE/.test(navigator.appVersion) &&
!/Opera/.test(navigator.userAgent) ) }

var IEVersion = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1];
}


I think this will only work in IE 4.0+ though (haven't tested it on IE 3.x)

And any other browser that has the letters MSIE in the userAgent string,
which makes it worthless.
 
A

Andrew Poulos

Randy said:
Andrew Poulos said the following on 8/4/2005 9:31 AM:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.


It's about as robust as taking a wild guess at what the browser is. The
navigator object is useless in trying to determine the environment, use
object detection instead.
Currently IE does not support transparency on PNG images at a bit depth
greater than 8. There's a "filter" that can be applied that allows
transparency but only if the IE version is 5.5+. If it's less than 5.5 I
need to use an albeit poorer quality 8 bit PNG.

I'm using a conditional comment to "know" it's IE. Should I just use
another conditional comment to "know" if the version is less than 5.5,
or is there a better way?

Andrew Poulos
 
C

cwdjrxyz

Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

As others have pointed out, javascript can not be dependend on anymore
to detect IE or the version thereof.The reason is that there is no
control over what a browser maker can write in the navigator object,
and many browser makers have greatly abused this object. One of the
worst offenders is Opera, but they are not the only one.

You might consider using the Microsoft conditonal as described at
http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp
.. This allows you to detect if the browser is IE and what version if
you wish. To other browsers, this special conditional comment appears
just as a regular comment. This special Microsoftese passes the W3C
validator as long as it includes the normal open and close comment
tags. However some of the several variations, including some with the
not operator ! are not surrounded by complete open and close comment
tags, and thus do not validate. The Microsoft conditional comment works
properly on my seven latest browsers, and even on the NN 4.8 relic.
However it is not likely to distinguish between the basic IE6 browser
and slight modifications thereof such as MSN9 and MyIE2. However, there
would usually be no need to detect the variations, as they respond to
web pages in the same way with rare exceptions.
 
K

Kevin Newman

Randy said:
Kevin Newman said the following on 8/4/2005 11:05 AM:
Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Andrew Poulos


if (/MSIE/.test(navigator.appVersion) &&
!/Opera/.test(navigator.userAgent) ) }

var IEVersion = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1];
}


I think this will only work in IE 4.0+ though (haven't tested it on IE
3.x)

And any other browser that has the letters MSIE in the userAgent string,
which makes it worthless.

Actually, it will only detect browsers that have MSIE in the appVersion
string ;-) - and it doesn't check to make sure navigator, and the
properties are available - Ivo had a point though, feature sniffing is a
better idea - however, there are times where that doesn't work...
 
K

Kevin Newman

Ivo said:
Andrew said:
Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.

Anything relying on the navigator properties is by definition far from safe
or robust, as the navigator identifier strings can easily be spoofed with
the express purpose of making you think you are dealing with a different
browser. Many browsers even ship spoofed.

Try feature detection. If a feature does not exist in one version of
JScript, but does in another, testing for its availability will tell you
something the version of script, which in turn is a clue towards determining
the version of the browser.
Which browsers runs which JScript versions, and which features come with
which version, is all listed here:
<URL:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriversioninform
ation.asp >

As of Internet Explorer 5.0, there is also a native function ScriptEngine()
which gives the exact number of the JScript version in use. See
<URL:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsfctScriptEngine.
asp >
or
<URL: http://4umi.com/web/javascript/jscript.htm >

hth
Ivo


You are right I should have mentioned something about that, instead of
simply answering the question. However, there are times where detecting
features isn't possible.

Kevin N.
 
R

Randy Webb

Andrew Poulos said the following on 8/4/2005 6:55 PM:
Randy said:
Andrew Poulos said the following on 8/4/2005 9:31 AM:

Is there a safe way to get the version of IE? I've done a google and
found this code:

var version=0
if (navigator.appVersion.indexOf("MSIE") != -1) {
temp = navigator.appVersion.split("MSIE");
version = parseFloat(temp[1]);
}

but I have no idea how "robust" it is.


It's about as robust as taking a wild guess at what the browser is. The
navigator object is useless in trying to determine the environment, use
object detection instead.

Currently IE does not support transparency on PNG images at a bit depth
greater than 8. There's a "filter" that can be applied that allows
transparency but only if the IE version is 5.5+. If it's less than 5.5 I
need to use an albeit poorer quality 8 bit PNG.

I'm using a conditional comment to "know" it's IE. Should I just use
another conditional comment to "know" if the version is less than 5.5,
or is there a better way?

That is the best way since only IE will ever recognize it (for now anyway).
 
R

Randy Webb

Kevin Newman said the following on 8/4/2005 10:22 PM:
Ivo wrote:




You are right I should have mentioned something about that, instead of
simply answering the question. However, there are times where detecting
features isn't possible.

Huh? Example?

Even this (the OP) has a feature detection answer. It is to use IE
specific conditional comments.
 
K

Kevin Newman

Kevin Newman said the following on 8/4/2005 10:22 PM:
Randy said:
Huh? Example?

I created a script that keeps a bookmarkable history for AJAX and flash
apps. It does this by creating a new hash value on the url string. There
are various bugs and quirks associated with this - IE 5.0 doesn't take a
new hash value unless their is a corresponding anchor on the page, IE
5.5 and 6.0 do not generate a history when the hash is set, so you have
to use the iframe method as a backup - the iframe method doesn't work in
Opera or Mozilla, because of various security and history bugs. Various
things keep any of these methods from working in Safari (I haven't found
a fix for that yet)

There is not effective way to check for all of these bugs and quirks, so
I created a generic code path that should work in most browsers (I'm
guessing that just setting the hash should work, though I haven't been
able to find a standard that defines this behavior), then I added
special cases for workarounds on various browsers. Currently there are
only fixes for IE, which could be hidden from others with conditional
comments, but there will be other fixes for other platforms, so I just
used the navigator strings for consistency, since I will be adding more
fixes for other platforms when I figure out how to get it to work (like
Safari).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top