yodaisgreen
yodaisgreen

Reputation: 2310

How do you disable phone number detection in mobile safari

I have tried to disable phone number detection in safari for my web app but it still shows 7 character strings comprised of numbers as phone numbers. I used the apple provided meta tag but no joy.

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

Anyone else run into this problem and work around it?

Thanks.

Update: It looks like it does not detect phone numbers in safari but rather when I save the page as an icon and run it from the home screen.

Upvotes: 12

Views: 16947

Answers (5)

Kevin Franklin
Kevin Franklin

Reputation: 187

Are you loading this in a UIWebView? If so, you need to set the property for dataDetectorTypes. e.g:

webView.dataDetectorTypes = UIDataDetectorTypeNone

Valid detector types are here.

Search for UIWebView on apple's site for a description of how to set the property there.

-Kevin

Upvotes: 13

Nithinbemitk
Nithinbemitk

Reputation: 2730

Try this Code,

webView.dataDetectorTypes = UIDataDetectorTypeNone;

This may help you.

Upvotes: 2

Boyds
Boyds

Reputation: 441

We had a similar problem on our JQM/Cordova app. We had a calculator built into the app and whenever the amount was more than seven digits the data would be in blue with an underline underneath and when you click on the data a pop up appeared and gave you the option to call. We simply added the meta tag as described in the opening question & it worked.

Just adding some thought here in case anybody else has a similar issue with Safari detecting 7 stringed data as telephone numbers.

Upvotes: 6

yodaisgreen
yodaisgreen

Reputation: 2310

OK. After quite a bit of futzing I think I found a strange work around. The problem with using dataDetectorTypes is that it will disable phone number detection for the whole uiwebveiw.

After trying datadetectors="off" and x-apple-data-detectors="false" attribute on span and a tags I finally stumbled on something that seems to prevent phone number detection.

If I wrap my text in an a tag with an href="#" apple seems to leave it alone.

Upvotes: 5

Peter Smeekens
Peter Smeekens

Reputation: 664

Try and add this to YourProjectAppDelegate.m

// ...

- (void)webViewDidStartLoad:(UIWebView *)theWebView 
{
    theWebView.dataDetectorTypes = UIDataDetectorTypeAll ^ UIDataDetectorTypePhoneNumber;    
    return [ super webViewDidStartLoad:theWebView ];
}

// ...

Did the trick for me..

Upvotes: 1

Related Questions