views:

477

answers:

2

I have a WebView displaying a HTML page, linking to a CSS file.

The CSS file makes use of the pseudoclasses :active and :hover for rollover effects.

Q. How can I tell, in my WebView, when :active and :hover have been called? I would like to intercept these calls and act on them programmatically within Cocoa.

Thanks.

A: 

I'm looking in the 2.2 SDK docs, and I don't see anything in the UIWebViewDelegate protocol. The best hope of accomplishing this maybe the instance method in UIWebView called stringByEvaluatingJavaScriptFromString. Unfortunately that would probably imply some kind of polling, as there seems to be no way to define an Objective-C method that JavaScript could call back on for such an event. I might be wrong, but I don't think it can be done (in 2.2).

dlamblin
“2.2 SDK”? :hover, in particular, would not make much sense on a touch-based device. I think it's reasonable to assume that the questioner is talking about the Mac.
Peter Hosey
+1  A: 

:active and :hover aren't calls; they're CSS pseudo-classes, for use in CSS selectors. You use them in CSS to select elements to style. They're adjectives, not verbs.

Try adding JavaScript event handlers to the elements instead. You can use a WebScriptObject to project some of your Cocoa methods into the JavaScript space for use from the event handlers.

Peter Hosey
Yeah what he said. :active is just onmousedown and :hover is onmouseover, more or less
SpliFF
Thanks for the help. I went with the WebScriptObject approach, calling myCococa code on mouseOver and onClick event handlers. Cheers.
SirRatty