禁用UIWebView中特定HTML元素的数据检测器
是否有人知道是否可以在UIWebView中为特定的HTML元素禁用电话号码,电子邮件地址等数据检测器?
Does anyone know if it's possible to disable the data detectors for phone numbers, email addresses etc in a UIWebView, for specific HTML elements only?
我想要检测器对于加载到UIWebView中的大多数内容都是活动的,但在某些区域禁用它。
I'd like the detectors to be active for most of the content loaded into the UIWebView, but disable it in certain areas.
如果这是可能的,我假设它会实现通过在加载的内容中使用HTML属性(而不是设置某种UIWebView属性),例如
If this is possible, I'm assuming it would be achieved by using an HTML attribute in the loaded content (rather than setting some sort of UIWebView property), e.g.
<html>
<body>
<h1 datadetectors="off">Header text with number 9123 3456</h1>
<p>Body text with number 9872 4567</p>
</body>
</html>
在此示例中,< p>中的数字由于设置 webview.dataDetectorTypes = UIDataDetectorTypeAll
,将被检测为电话号码,而< h1>中的数字将被检测为电话号码。不会。
In this example, the number in the <p> would be detected as a phone number due to setting webview.dataDetectorTypes = UIDataDetectorTypeAll
, whereas the number in the <h1> would not.
你可以把属性
x-apple-data-detectors="false"
但遗憾的是似乎只适用于标签。
我最终使用了这个解决方案:
but unfortunately this seems to work only for tags. I ended up using this solution:
<a href="#" x-apple-data-detectors="false">666-777-777</a>
除了禁用电话号码检测外,还可以防止地址和其他检测运行。
besides disabling the telephone numbers "detection", this also prevents adresses and other detection to run.