简体   繁体   中英

Use of Parentheses in HTML with "href=tel:"

Surprised I can't find a definitive answer about this anywhere online: I am setting up a translated HTML page in French with a different contact number that begins with "+33 (0)." Since I can't personally test it on this number -- a canonical question: can I get away with an anchor tag that begins <a href="tel:+33(0)..." ie has a number contained in parentheses with the remaining numbers following and have the link work?

Good question. Finding a clear, authorative answer regarding href="tel:" specifically is difficult.

RFC 3986 (Section 2.2) defines parenthesis as "reserved sub-delims". This means that they may have special meaning when used in certain parts of the URL. The RFC says:

URI producing applications should percent-encode data octets that correspond to characters in the reserved set unless these characters are specifically allowed by the URI scheme to represent data in that component. If a reserved character is found in a URI component and no delimiting role is known for that character, then it must be interpreted as representing the data octet corresponding to that character's encoding in US-ASCII.

(Emphasis mine)

Basically, you can use any character in the US-ASCII character set in a URL. But, in some situations, parentheses are reserved for specific uses, and in those cases, they should be percent-encoded. Otherwise they can be left as is.

So, yes, you can use parentheses in href="tel:" links and they should work across all browsers. But as with any web standard in the real world, performance relies on each browser correctly implementing that standard.

However , regarding your example ( <a href="tel:+33(0)... ), I would steer clear of the format you have given, that is:

[country code]([substituted leading 0 for domestic callers])[area code][phone number]

While I was unable to find a definitive guide to how browsers handle such cases, I think you will find, as @DigitalJedi has pointed out, that some (perhaps all?) browsers will strip the parentheses and leave the number contained therein, resulting in an incorrect number.

Eg

<a href="tel:+33(0)1234567890">+33 (0) 123 456 7890</a>

will/may result in a call to +3301234567890. Will this still work? Maybe? We're getting into phone number routing territory now.

Some browsers/devices may be smart enought to figure out what is intended and adapt accordingly, but I would play it safe and instead simply use:

[country code][area code][phone number]

Eg

<a href="tel:+331234567890">+33 (0) 123 456 7890</a>

There is no downside (that I know of) to having your local users dialing the international country code - it will result in the same thing as if the had omitted it and substituted the leading zero.

Here is some semi-related, useful information regarding browser treatment of telephone links: https://css-tricks.com/the-current-state-of-telephone-links/

The () in the href attribute should not be a problem: (href-wise)

http://example.com/test(1).html

HOWEVER, if I do a href="tel:+000 (1) 000 000" , after clicking the link on phone, the dial on my phone will show +0001000000 This is tested and confirmed on a Android device

This means that the parentheses are removed, as well as the spaces.

But this could still vary because of different OS on the phone.

PS:

If you think the + in your number is an issue... I did test this too , and the + does not have any unexpected behavior.

MORE: href="tel:" and mobile numbers

我阅读并记住正确的格式应该是:+33.1 23 45 67 89 但我找不到来自哪里。

According to ITU-T E.123 Section 7.2 Use of parentheses

The ( ) should not be used in an international number.

So (0) should not be included at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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