开发者

Disabling data detectors for a specific HTML element in a UIWebView

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?

I'd like the detectors to be active for most of the content loaded into the UIWebView, but disable it in certain areas.

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>

In this example,开发者_JS百科 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.


you should use <meta name = "format-detection" content = "telephone=no">

Hope it helps


you can put the attribute

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.


If you control the web content you can use jscript (via jquery) to write your own data detectors. If you don't control the content you could insert and execute the jscript using stringByEvaluatingJavaScriptFromString: once webViewDidFinishLoad: is called.


In WKWebView Disable all Data Detector Types in Attributes inspector. This will solve your problem


Since an "a" tag will be inserted for you with the x-apple-data-detectors in it, you could write the tag yourself with x-apple-data-detectors set to false.

Original code:

<div class="my_time">17:02</div>

will be transformed to:

<div class="my_time">
<a href="x-apple-data-detectors://1" dir="ltr" 
   x-apple-data-detectors="true" 
   x-apple-data-detectors-type="calendar-event" 
   x-apple-data-detectors-result="1" 
   style="color: rgb(169, 169, 169); 
   text-decoration-color: rgba(169, 169, 169, 0.258824);">14:18
</a>
</div>

You can prevent this by writing your code as following...

<div class="my_time">
  <a x-apple-data-detectors="false" style="text-decoration: none">17:02</a> 
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜