简体   繁体   English

使用webkit-tap-highlight查找元素

[英]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. 当您点击并按住UIWebView(或移动版Safari)中的链接时,它会在灰色文本框中突出显示该链接。

You can control the styling of this with the webkit-tap-highlight css property. 您可以使用webkit-tap-highlight css属性控制其样式。

What I'd like to know is if it is possible to either: A. Listen to an event for when something is highlighted. 我想知道的是,是否有可能:A。在某事突出时听一个事件。 B. At a given time, find any elements that are currently highlighted. B.在给定时间,找到当前突出显示的任何元素。

Is this currently possible? 这目前可能吗?

Although the iPhone is a touch device, the mouseover event will be triggered when the element is highlighted. 虽然iPhone是触控设备,但在突出显示元素时会触发鼠标悬停事件。 So, you can use javascript to listen the mouseover event. 因此,您可以使用javascript来监听鼠标悬停事件。

Looks like this guy figured it out using window.getSelection() and text.anchorNode.textContent.substr(text.anchorOffset, text.focusOffset - text.anchorOffset) : 看起来这个人用window.getSelection()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/ 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 . 本文也被选为另一篇StackOverflow帖子中的工作答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM