Check for support for hover on non <a> elements

R

Robert Mark Bram

Hi All!

Problem I began with: Netscape/Opera supports hover for different elements,
IE only supports hover for <a> and I want to use hover for <td class="menu">

I then found a fix using some Javascript here:
http://webpages.charter.net/mmmbeer/code/arbitrary-hover/

It works ok for IE now.

Problem I now have: I don't want the script to run in a browser that does
support hover for <td>.

In other words I noticed that the script was still running for Netscape and
Opera - but I would prefer to let those browser's native hover support to
work since I notice that in some cases the script can introduce lag at
loading time.

I don't want to sniff for IE: I know how unreliable browser sniffing is. I
would rather sniff for the lack of hover support.

Can anyone give me clues as to how this might be done?

Any help would be most appreciated!

Rob
:)
 
R

Robert Mark Bram

Hi Mark,

Thanks for the reply!
You could use conditional comments. It's kind of browser sniffing, but
it is reliable.
http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp

Well, this seems to work ok:

<!--[if IE 5]>
<script language="javascript" type="text/javascript"
src="../bin/ieHoverFix.js"></script>
<![endif]-->

It feels like a hack.. *grin* but then again, just about every single
'advanced' thing I try to do in Javascript lately ends up feeling like a
hack! *sigh*

Rob
:)
 
M

Mark Parnell

<!--[if IE 5]>
<script language="javascript" type="text/javascript"
src="../bin/ieHoverFix.js"></script>
<![endif]-->

Yep, that's the one. Note that the above will only affect IE5.x, not
It feels like a hack..

It is. ;-)
*grin* but then again, just about every single
'advanced' thing I try to do in Javascript lately ends up feeling like a
hack! *sigh*

<g>
 
M

Mark Parnell

<!--[if gte IE 5]-->

No, that is then a normal HTML comment, so other browsers will still see
the stuff in between. If you wanted other browsers to see it and *not*
IE, you could do <!--[if !gte IE 5]-->

Fun for the whole family. :)
 
R

rf

Mark Parnell said:
<!--[if gte IE 5]-->

No, that is then a normal HTML comment, so other browsers will still see
the stuff in between. If you wanted other browsers to see it and *not*
IE, you could do <!--[if !gte IE 5]-->

<runs to look at MS documentation>

Ah, so *that's* how the buggers work. Who'd have guessed :)
Fun for the whole family. :)

Indeed.
 
M

Mick White

Robert Mark Bram wrote:

Well, this seems to work ok:

<!--[if IE 5]>
<script language="javascript" type="text/javascript"
src="../bin/ieHoverFix.js"></script>
<![endif]-->

Windows only, though.
Mick
 
M

Michael Wilcox

Mark said:
Yep, that's the one. Note that the above will only affect IE5.x, not
IE6. Change the first line to <!--[if gte IE 5]> and it will work in
anything from IE5 up.

Would it be better to use <!--[if IE]> to detect all versions of IE?
 
G

Grant Wagner

Mick said:
Robert said:
Well, this seems to work ok:

<!--[if IE 5]>
<script language="javascript" type="text/javascript"
src="../bin/ieHoverFix.js"></script>
<![endif]-->

Windows only, though.
Mick

That's the whole point. He wants some hover behaviour to be
included only for IE. To other browsers the above code looks like
a comment. Only IE evaluates it, only IE will load the extenal JS
file. If IE7 (or 6.5 or 6.0SP2 or whatever) starts supporting
td:hover, he can change the condition to be something like:

<!--[if lt IE 7]>
 
M

Mick White

Grant said:
Mick White wrote:



That's the whole point. He wants some hover behaviour to be
included only for IE.

The comments are ignored on IE Mac...
Mick

To other browsers the above code looks like
a comment. Only IE evaluates it, only IE will load the extenal JS
file. If IE7 (or 6.5 or 6.0SP2 or whatever) starts supporting
td:hover, he can change the condition to be something like:

<!--[if lt IE 7]>
 
L

Lasse Reichstein Nielsen

Michael Wilcox said:
Would it be better to use <!--[if IE]> to detect all versions of IE?

Do you plan to maintain the page in all future?

Otherwise, I would recommend:
<!--[if lt IE 7]>
so that you don't block future versions unnecessarily.

/L
 
M

Mark Parnell

That's not a problem, though, because IE Mac's rendering engine is
different from that of IE Dows.

Does IE Mac support :hover on elements other than <a>?
 
R

Richard Cornford

Toby said:
Nope. IIRC it's only KHTML, Gecko and Opera 6+
(perhaps 5.1x?) that do.

How does Mac IE get on with VBScirpt? If it can understand it then maybe
a VBScirpt implementation would be successfully ignored by all non-IE
browsers. Or VBScript being used to write the script tags into the page
(so it wouldn't happen on non-IE browsers).

Or maybe specifying the language type as "text/jscript" would be enough
to keep non-IE browsers from attempting to load/use the external JS
file.

Richard.
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top