简体   繁体   English

在 HTML 中使用带有 "href=tel:" 的括号

[英]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)."很惊讶我在网上的任何地方都找不到关于这个的明确答案:我正在用法语设置一个翻译的 HTML 页面,其中有一个以“+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?由于我无法在这个数字上亲自测试它 - 一个规范的问题:我可以使用以<a href="tel:+33(0)..."开头的锚标签,即在括号中包含一个数字剩下的数字在后面并且链接有效吗?

Good question.好问题。 Finding a clear, authorative answer regarding href="tel:" specifically is difficult.找到关于href="tel:"的明确、权威的答案是很困难的。

RFC 3986 (Section 2.2) defines parenthesis as "reserved sub-delims". RFC 3986(第 2.2 节)将括号定义为“保留的子分隔符”。 This means that they may have special meaning when used in certain parts of the URL.这意味着它们在 URL 的某些部分使用时可能具有特殊含义。 The RFC says: RFC 说:

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. URI 生成应用程序应该对与保留集中的字符对应的数据八位字节进行百分比编码,除非URI 方案明确允许这些字符表示该组件中的数据。 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.如果在 URI 组件中发现保留字符,并且该字符没有已知的定界角色,则必须将其解释为表示与该字符在 US-ASCII 中的编码相对应的数据八位字节。

(Emphasis mine) (强调我的)

Basically, you can use any character in the US-ASCII character set in a URL.基本上,您可以在 URL 中使用US-ASCII 字符集中的任何字符。 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.所以,是的,您可以在href="tel:"链接中使用括号,它们应该适用于所有浏览器。 But as with any web standard in the real world, performance relies on each browser correctly implementing that standard.但与现实世界中的任何 Web 标准一样,性能依赖于每个浏览器正确实现该标准。

However , regarding your example ( <a href="tel:+33(0)... ), I would steer clear of the format you have given, that is:但是,关于您的示例( <a href="tel:+33(0)... ),我会避开您提供的格式,即:

[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.虽然我无法找到有关浏览器如何处理此类情况的明确指南,但我想您会发现,正如@DigitalJedi 指出的那样,某些(也许是全部?)浏览器会去掉括号并保留其中包含的数字,从而导致一个不正确的数字。

Eg例如

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

will/may result in a call to +3301234567890.将/可能导致拨打 +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/以下是有关电话链接的浏览器处理的一些半相关的有用信息: https : //css-tricks.com/the-current-state-of-telephone-links/

The () in the href attribute should not be a problem: (href-wise) href属性中的()应该没有问题:(href-wise)

http://example.com/test(1).html 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但是,如果我执行a href="tel:+000 (1) 000 000" ,单击手机上的链接后,手机上的拨号将显示+0001000000这是在 Android 设备上测试和确认的

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: 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更多: href="tel:" 和手机号码

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

According to ITU-T E.123 Section 7.2 Use of parentheses根据ITU-T E.123 Section 7.2 括号的使用

The ( ) should not be used in an international number. ( ) 不应用于国际号码。

So (0) should not be included at all.所以(0)根本不应该包括在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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