防止在iOS設備中的Safari將數字識別為電話號碼


在測試中發現iPad上的Safari總會把長串數字識別為電話號碼,文字變成藍色,點擊還會彈出菜單添加到通訊錄。

別的地方倒也罷了,如果在用戶名中出現數字(手機注冊新浪微博的話用戶名就是“手機用戶xxxxxxxx”),版式會很惡心。

經過測試在a標簽中的長串數字不會識別為電話,於是給出現用戶名但沒有鏈接的地方嵌套一個無動作的a標簽,臨時解決了這個問題。

但是這樣增加了額外的標簽,代碼的語義性變得很差,而且對大段文字不能用這個方法。

今天無意中撞進Safari的官網,發現了safari有個私有meta屬性可以解決這個問題:

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

官網的說明如下: How do I disable automatic detection of phone numbers in webpages? In Safari on iPhone, phone numbers are automatically detected and transformed into links that dial the phone number when tapped. If you have strings of numbers in your webpage that should not be automatically detected as phone numbers, you can choose to disable this feature on the entire page by adding the meta tag shown in Listing 12.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM