A valid use for browser detection?

M

Michael Winter

As many of you know, IE has poor support for CSS 2, including the dynamic
pseudo-class, :hover. This could easily be emulated with an intrinsic
event, but how can you tell that it's required? You could skip the
detection by always adding an event handler but this would be a waste of
time for browsers that do implement the pseudo-class.

Any suggestions? Would it be best to avoid the :hover pseudo-class and
implement a full event-based solution, or is there a way to detect
support? Can this be extended to other CSS selectors, and even
declarations?

Mike
 
L

Lasse Reichstein Nielsen

Michael Winter said:
As many of you know, IE has poor support for CSS 2, including the
dynamic pseudo-class, :hover. This could easily be emulated with an
intrinsic event, but how can you tell that it's required?

Only by precisely detecting IE 6 or older.
For IE 5.5 and later, you can use conditional comments (currently not
implemented by any other browser afaik), or you can use behaviors
( said:
You could skip the detection by always adding an event handler but
this would be a waste of time for browsers that do implement the
pseudo-class.

Yes, using Javascript should only ever be a fallback for older browsers
where you know that it will work. New browsers are supposed to get it right,
and should by default not be included in the fallback.
Any suggestions? Would it be best to avoid the :hover pseudo-class

No, use the standard, that's what it is there for.
and implement a full event-based solution,

Only if you want to. Your page should work without it, since you can't
expect Javascript to be available either.
or is there a way to detect support? Can this be extended to other
CSS selectors, and even declarations?

Probably :)
/L
 
M

Michael Winter

Only by precisely detecting IE 6 or older.
For IE 5.5 and later, you can use conditional comments (currently not
implemented by any other browser afaik), or you can use behaviors
(<URL:http://msdn.microsoft.com/workshop/author/behaviors/overview.asp>).

I thought it might involve something nasty like that.
Yes, using Javascript should only ever be a fallback for older browsers
where you know that it will work. New browsers are supposed to get it
right, and should by default not be included in the fallback.


No, use the standard, that's what it is there for.

I completely agree with both of these points, and they represent my
preferred approach. However, if someone were to argue a valid case against
it, I'd be prepared to accept it. Thankfully, you didn't. :) Here's hoping
no-one else does...
Only if you want to.

I'd really rather not. IE users can do without, until that cold day in
Hell when Microsoft implements CSS 2. It won't degrade their use of the
site, either way.
Your page should work without it, since you can't
expect Javascript to be available either.

Of course.

A nice and concrete answer, there. :p

I was really looking for a simple solution that I might have overlooked,
but it would appear that any detection would involve something convoluted
that I could do without.

Unless someone else has something different to add, I think that would
conclude this thread.

Thank you, Mr Nielsen.

Mike
 
D

DU

Michael said:
As many of you know, IE has poor support for CSS 2, including the
dynamic pseudo-class, :hover.

No, I did not know that. AFAIK, a:hover always was well supported by MSIE 6.

This could easily be emulated with an
intrinsic event, but how can you tell that it's required? You could skip
the detection by always adding an event handler but this would be a
waste of time for browsers that do implement the pseudo-class.

Any suggestions? Would it be best to avoid the :hover pseudo-class and
implement a full event-based solution, or is there a way to detect
support? Can this be extended to other CSS selectors, and even
declarations?

Mike

You could build a custom behavior for this and include it in a
stylesheet... or you could create an accurate custom script function to
compensate such MSIE absence of support... or you could give an url and
explain what exactly you're trying to achieve.

DU
 
M

Michael Winter

No, I did not know that. AFAIK, a:hover always was well supported by
MSIE 6.

The :hover pseudo-class applies to virtually every HTML element, not just
anchors. You could apply it to a DIV, a TABLE, a list. You can even apply
it to BODY. I think the only exceptions would be HEAD-based elements (for
obvious reasons) and SCRIPT elements.

As a matter of fact, a:hover works with IE 5.5, too but only if you use
a:hover. #an-anchor:hover fails.

[snip]
You could build a custom behavior for this and include it in a
stylesheet... or you could create an accurate custom script function to
compensate such MSIE absence of support... or you could give an url and
explain what exactly you're trying to achieve.

The missing functionality isn't important enough to require such dogged
attempts to compensate for IE's shortcomings. It was also a general
question that revolved around CSS feature support in general: if the
principals of script feature detection could be applied in some fashion.

Thank you for the suggestions, however. If it was more mission critical, I
would certainly investigate them further, but the effort simply isn't
justified.

Mike
 
M

Michael Winter

Actually using behaviors is not difficult at all:
http://www.vladdy.net/Demos/IEPseudoClassesFix.html

I suppose I did just dismiss them out of hand, but it seems so
unreasonable to ask developers to use such an obscure method of doing
something that most other browsers can do the simple way.

Thank you for sharing that page.

Mike


By the way, para. 1, sentence 1 should read: "...forced onto the
unsuspecting public by Microsoft Corporation..." :)
 
J

Jim Ley

I suppose I did just dismiss them out of hand, but it seems so
unreasonable to ask developers to use such an obscure method of doing
something that most other browsers can do the simple way.

Behaviors are not recommended by microsoft any more, they suffer from
terrible memory leaks and are truly awful. Avoid!

Jim.
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top