Find elements with webkit-tap-highlight


When you tap and hold on a link inside a UIWebView (or mobile safari), it highlights the link in a gray text box.

You can control the styling of this with the webkit-tap-highlight css property.

What I'd like to know is if it is possible to either: A. Listen to an event for when something is highlighted. B. At a given time, find any elements that are currently highlighted.

Is this currently possible?

Looks like this guy figured it out using window.getSelection() and text.anchorNode.textContent.substr(text.anchorOffset, text.focusOffset - text.anchorOffset):

http://zaldzbugz.wordpress.com/2010/05/31/how-to-get-the-highlighted-text-in-uiwebview/

This article was also chosen as a working answer in another StackOverflow post.


Although the iPhone is a touch device, the mouseover event will be triggered when the element is highlighted. So, you can use javascript to listen the mouseover event.