473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

getting IE version

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
Aug 4 '05 #1
11 2660
Andrew Poulos wrote:
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.
Aug 4 '05 #2
Ivo
"Kevin Newman" wrote
Andrew Poulos wrote:
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...iversioninform
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...ctScriptEngine.
asp >
or
<URL: http://4umi.com/web/javascript/jscript.htm >

hth
Ivo
Aug 4 '05 #3
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 4 '05 #4
Kevin Newman said the following on 8/4/2005 11:05 AM:
Andrew Poulos wrote:
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 4 '05 #5
Randy Webb wrote:
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
Aug 4 '05 #6


Andrew Poulos wrote:
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/a...omment_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.

Aug 4 '05 #7
Randy Webb wrote:
Kevin Newman said the following on 8/4/2005 11:05 AM:
Andrew Poulos wrote:
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...
Aug 5 '05 #8
Ivo wrote:
"Kevin Newman" wrote
Andrew Poulos wrote:
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...iversioninform
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...ctScriptEngine.
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.

Aug 5 '05 #9
Andrew Poulos said the following on 8/4/2005 6:55 PM:
Randy Webb wrote:
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).

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 5 '05 #10
Kevin Newman said the following on 8/4/2005 10:22 PM:
Ivo wrote:


<--snip-->
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...ctScriptEngine.

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.


Huh? Example?

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 5 '05 #11
Kevin Newman said the following on 8/4/2005 10:22 PM:
However, there are times where detecting features isn't possible.

Randy Webb wrote: 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).
Aug 15 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrik Carlsson | last post by:
I have a problem using Xerces with a template for a generic page-header getting a sub-tree as argument. The same stylesheet is working flawlessly in IE and Mozilla, though it would be nice to have...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
0
by: shawnk | last post by:
I downloaded and installed the new SQL Server Express Manager tool but it had problems with the latest 'released version of .NET (version I have is 2.0.40607). I looked on MSDN websites but did...
2
by: nfr | last post by:
I keep getting the following warning in my compile: Warning: The dependency 'WBWebServices, Version=1.0.1289.13943, Culture=neutral' in project 'WBWin' cannot be copied to the run directory...
2
by: kris | last post by:
Hello, We're porting some old code to our new C# .NET project and are having trouble getting the file version of a non-.NET EXE file using C# .NET code. In our old code, we were using the...
2
by: William Gower | last post by:
I am trying to display a page that has a data grid on it. I get this message Description: An error occurred during the processing of a configuration file required to service this request....
2
by: JIM.H. | last post by:
Hello, I know the user I give in the connection string is the database admin, why am I getting the following message? Server Error in '/' Application...
0
by: MSK | last post by:
Dear all, Continued to my earlier mail regarding "Breaking points are not getting hit in ASP.NET " , I got some idea from net. Can anyone give me more idea on this? Just to remind the issue:...
2
by: Dylan Parry | last post by:
Hi, Is there a way of getting the date that an assembly was last compiled? I am trying to help myself to remember what version of a particular assembly my Web applications are using, so I've...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.