IE 5.0 supports overflow-x/y (and IE 4 may also).
... 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.