473,508 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Browser version detection: How?

I've have got this script, the only thing I want to be changed is the first
part. It has to detect IE version 6 instead of just "Microsoft Internet
Explorer". Can somebody help me out?
I tried "Microsoft Internet Explorer 6" but that doesn't work.

<SCRIPT LANGUAGE="Javascript">
<!--
bName = navigator.appName;
if (bName =="Microsoft Internet Explorer") {
document.write('<link media="screen" rel="STYLESHEET" type="text/css"
href="stylesheet1.css">')
} else {
document.write('<link media="screen" rel="STYLESHEET" type="text/css"
href="stylesheet2.css">')
}
//-->
</SCRIPT>
Jul 23 '05 #1
8 4528
On Mon, 18 Oct 2004 09:14:11 +0200, R. Smits <NOMAIL@NOMAIL> wrote:
I've have got this script, the only thing I want to be changed is the
first part. It has to detect IE version 6 instead of just "Microsoft
Internet Explorer". Can somebody help me out?
I tried "Microsoft Internet Explorer 6" but that doesn't work.
Scripting browser detection is highly unreliable, as browsers can, and do,
spoof IE. It would be more reliable to use conditional comments[1].

<link rel="stylesheet" type="text/css" href="stylesheet2.css"
media="screen">

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="stylesheet1.css"
media="screen">
<[endif]-->

This would load stylesheet2 in all browsers, and stylesheet1 in only IE6.
The rules in stylesheet1 would override conflicting rules in stylesheet2.
<SCRIPT LANGUAGE="Javascript">
The language attribute has been deprecated in favour of the (required)
type attribute for quite some time now. Don't use it.

<script type="text/javascript">
<!--
The practice of hiding scripts is similarly out-dated. There are no user
agents now in use that will render the contents of the script. All
browsers understand what a SCRIPT element is, even if they will just
ignore it (they don't support scripting).
bName = navigator.appName;


You might want to read the FAQ (<URL:http://jibbering.com/faq/>). Browser
detection, and what you should do instead, is covered there.

[snip]

Hope that helps,
Mike
[1]
<URL:http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp>

Only IE 5 and later support conditional comments.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
> I've have got this script, the only thing I want to be changed is the
first
part. It has to detect IE version 6 instead of just "Microsoft Internet
Explorer". Can somebody help me out?


The question is - do you really need exactly IE 6.x or would it be enough to
get some IE 4.x or higher version?
Consider, that if only asking for IE 6.x an IE 5.x e. g. would get
stylesheet2.css.
So I think you should use one stylesheet file for all IE 4.x or higher
version and some other stylesheet for all none-IE browsers (assuming that
there is no IE older than 4.x in use today).
Or do you really have such special stylesheet features that are only
supported by IE 6.x?

Nice greetings from
Thomas
Jul 23 '05 #3
"Thomas Hoheneder" <th**************@gmx.de> wrote in message
news:cl**********@domitilla.aioe.org...
The question is - do you really need exactly IE 6.x or would it be enough to get some IE 4.x or higher version?
Consider, that if only asking for IE 6.x an IE 5.x e. g. would get
stylesheet2.css.
So I think you should use one stylesheet file for all IE 4.x or higher
version and some other stylesheet for all none-IE browsers (assuming that
there is no IE older than 4.x in use today).
Or do you really have such special stylesheet features that are only
supported by IE 6.x?


Yep, I defined a 'overflow-y'.
As far as I know IE 6 is the only browers which supports this.
(Am I correct?)
Jul 23 '05 #4
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opsf16aoe1x13kvk@atlantis...
On Mon, 18 Oct 2004 09:14:11 +0200, R. Smits <NOMAIL@NOMAIL> wrote:
I've have got this script, the only thing I want to be changed is the
first part. It has to detect IE version 6 instead of just "Microsoft
Internet Explorer". Can somebody help me out?
I tried "Microsoft Internet Explorer 6" but that doesn't work.
Scripting browser detection is highly unreliable, as browsers can, and do,
spoof IE. It would be more reliable to use conditional comments[1].

<link rel="stylesheet" type="text/css" href="stylesheet2.css"
media="screen">

<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="stylesheet1.css"
media="screen">
<[endif]-->

This would load stylesheet2 in all browsers, and stylesheet1 in only IE6.
The rules in stylesheet1 would override conflicting rules in stylesheet2.


I tried something like this inside one stylesheet, but it didn't work.
Something like this:

..scroll {
height: 450px;
display:block;
overflow: scroll;
overflow-y: scroll;
}
<SCRIPT LANGUAGE="Javascript">


The language attribute has been deprecated in favour of the (required)
type attribute for quite some time now. Don't use it.

<script type="text/javascript">
<!--


The practice of hiding scripts is similarly out-dated. There are no user
agents now in use that will render the contents of the script. All
browsers understand what a SCRIPT element is, even if they will just
ignore it (they don't support scripting).
bName = navigator.appName;


You might want to read the FAQ (<URL:http://jibbering.com/faq/>). Browser
detection, and what you should do instead, is covered there.

[snip]

Hope that helps,
Mike
[1]

<URL:http://msdn.microsoft.com/workshop/a...ccomment_ovw.a
sp>
Only IE 5 and later support conditional comments.


Thanks for your help.

Jul 23 '05 #5
> Yep, I defined a 'overflow-y'.
As far as I know IE 6 is the only browers which supports this.
(Am I correct?)


I am not sure, but I think you might be right. I tried it on IE 6 and it
worked, and on Mozilla Firefox it did not work.
So I think you want to have a query to detect IE 6.x on one side and all
other browsers on the other side. For the moment (where is no IE 7.x) I
would do this in the following way:

var strBVersion = new String(navigator.appVersion);
var bVersion = str.indexOf("MSIE 6");
if (bName == "Microsoft Internet Explorer" && bVersion != -1)
// IE 6.x
else
// some IE older than IE 6 or none IE browsers

But it could be (which is very presumably) an IE 7.x or something like that.
To support also this one, you should better modify the above instructions in
the following way to support all IE 6.x or higher versions - so a more
robust query would be:

var strBVersion = new String(navigator.appVersion);
var bVersion1 = str.indexOf("MSIE 6");
var bVersion2 = str.indexOf("MSIE 7");
if (bName == "Microsoft Internet Explorer" && bVersion1 != -1 && (bVersion1
!= -1 || bVersion2 != -1))
// IE 6.x or higher
else
// some IE older than IE 6 or none IE browser

Hope this helps you.

Nice greetings from
Thomas
Jul 23 '05 #6
> var bVersion = str.indexOf("MSIE 6");

I'm sorry, but "str.indexOf" must be replaced with "strBVersion.indexOf" in
both code variations.
Jul 23 '05 #7
Thomas Hoheneder wrote:
Yep, I defined a 'overflow-y'.
As far as I know IE 6 is the only browers which supports this.
(Am I correct?)

I am not sure, but I think you might be right. I tried it on IE 6 and it
worked, and on Mozilla Firefox it did not work.
So I think you want to have a query to detect IE 6.x on one side and all
other browsers on the other side.


No, you don't have to worry about the browser. If you use a CSS
definition that the browser doesn't understand, it ignores it. Meaning,
when any browser that encounters div { myOffTheWallAttribute: 0px;} it
will simply ignore it.

For the moment (where is no IE 7.x) I would do this in the following way:
And you would fail.
var strBVersion = new String(navigator.appVersion);
var bVersion = str.indexOf("MSIE 6");
if (bName == "Microsoft Internet Explorer" && bVersion != -1)
// IE 6.x
else
// some IE older than IE 6 or none IE browsers

You corrected the str. mistake, but where is bName defined?

This is the navigator.appVersion as reported by AOL 9.0, which passes
your test but it is *not* IE6.0

4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1)

I think what you were after was the appName, but this is what AOL reports:

Microsoft Internet Explorer

Again, its not Internet Explorer, but a shell of it. In any event, its
irrelevant to the question. That is the same appName as given by Opera
7 in IE spoof mode.
But it could be (which is very presumably) an IE 7.x or something like that.
To support also this one, you should better modify the above instructions in
the following way to support all IE 6.x or higher versions - so a more
robust query would be:

var strBVersion = new String(navigator.appVersion);
var bVersion1 = str.indexOf("MSIE 6");
var bVersion2 = str.indexOf("MSIE 7");
if (bName == "Microsoft Internet Explorer" && bVersion1 != -1 && (bVersion1
!= -1 || bVersion2 != -1))
// IE 6.x or higher
else
// some IE older than IE 6 or none IE browser


And it still won't work. See above.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #8
Thomas Hoheneder wrote:
Yep, I defined a 'overflow-y'.
As far as I know IE 6 is the only browers which
supports this. (Am I correct?)

IE 5.0 supports overflow-x/y (and IE 4 may also).

<snip> ... I would do this in the following way:

var strBVersion = new String(navigator.appVersion);
var bVersion = str.indexOf("MSIE 6");
if (bName == "Microsoft Internet Explorer" && bVersion != -1)
// IE 6.x
else
// some IE older than IE 6 or none IE browsers

But it could be (which is very presumably) an IE 7.x or
something like that. To support also this one, you should
better modify the above instructions in the following way
to support all IE 6.x or higher versions - so a more robust
query would be:
It has not been Microsoft's style to remove anything form IE once they
have introduced it, so overflow-x/y are likely to remain part of their
browser in future versions.
var strBVersion = new String(navigator.appVersion);
var bVersion1 = str.indexOf("MSIE 6");
var bVersion2 = str.indexOf("MSIE 7");
It might be another 2 years before we see the next IE version, but after
that they may produce a number of versions in rapid succession. So they
may be on IE 8 within a year of IE 7 (assuming they decide to use
sequential version numbers instead of some naming or coding system, as
appears to be recent fashion).

One of the more obvious flaws in browser detection is the anticipation
of future versions of browsers. The assumption that the next version of
IE will be identifiable as "MSIE 7", even if true, will still mean that
this code will need maintenance when the following version comes out.
if (bName == "Microsoft Internet Explorer" && bVersion1 != -1 &&
(bVersion1 != -1 || bVersion2 != -1))
// IE 6.x or higher
else
// some IE older than IE 6 or none IE browser

Hope this helps you.


It never helps to be recommending browser detection in any form, but
particularly based on properties of the - navigator - object. The
assumed relationships required for this style of detection are not even
true for current browsers. This particular 'test' will have
misidentified IceBrowser and NetFront as IE 6 by default, and may also
end up treating half a dozen other browsers as IE 6 depending on user
preference settings. It is really unrelated to the problem it is trying
to solve and as a result will be wide of the mark much of the time.

Feature detection testing is based around trying to determine support
for any particular feature of web browsers in a way that is closely
related to the problem (preferably by a one-to-one relationship). In
this case the question of interest is; does the browser support the
overflow-x/y style properties (and has nothing to do with whether that
browser actually is an IE version or not). That question might best be
answered by examining a - style - object, be it the style object
belonging to some DOM element, or retrieved from a style rule in the -
document.styleSheets - object. A browser that supports overflow-x/y - is
likely to manifest - overflowX/Y - properties on its - style - objects,
while a browser lacking support almost certainly will not. So, given a
reference to a - style - object, a discriminating feature detection test
that has a clear direct relationship with the browser's support for the
feature of interest would be:-

if( typeof aStyleObject.overflowY == 'string'){
... // browser can be expected to support overflow-y.
}

And like feature detection testing in general, not only does it answer
the question that needs to be answered (rather than some other question
that is assumed to be related to the first in some (often invalid) way),
it is also future proof as it no longer matters whether the next (or
subsequent) version of IE supports the feature (or indeed whether the
browser is a Microsoft browser at all). So instead of writing code that
you know will require future maintenance (when IE 8 is released) you are
writing code that stands a good chance of never needing looking at again
(once it is properly tested).

Of course CSS problems are best tacked with CSS techniques (as Randy
mentioned) rather than scripting.

Richard.
Jul 23 '05 #9

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

Similar topics

7
10046
by: Szar | last post by:
JS noob. I've seen plenty of browser detection scripts but they all seem to be slightly different and don't really fit my needs. I have various places where if the browser is IE I'd like to display...
17
2522
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this...
8
1669
by: Jimnbigd | last post by:
What is the recommended code to test browser type, for conditional processing in Javascript? I have seen tests for "document.all". I have seen tests for the actual browser name, or substrings in...
4
2547
by: trpost | last post by:
I am looking for a script using javascript to pull browser information including, browser type and version, OS info, plugins (flash, acrobat, media player, etc), java version, etc. that will work...
16
2325
by: petermichaux | last post by:
Hi, Does anyone have a a cross-browser setOpacity function that does not use browser sniffing? I looked at the Yahoo! UI function and it detects IE by looking for window.ActiveXObject. I also...
7
2984
by: Nathan Sokalski | last post by:
I want to make sure I am doing a browser detection that will work once IE7 is released. My current detection statement (written using VB.NET) is: If Me.Request.Browser.Browser.ToUpper() = "IE"...
1
2044
by: jaydev | last post by:
Hi, I am looking for code to detect and redirect to the corresponding browser download page if the clients uses old version, could anyone have a sample code for this? I want to use the...
4
2162
by: sjpolak | last post by:
sorry, I put the original text instead of my changed one in the previous mail sorry hello, I am new to this forum and a laymen. I have awebsite www.earlyflute.com. I make baroque flutes as you...
10
3233
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.