我需要为移动设备建立一个网页。只有一件事我还没想明白:我怎么才能通过点击文本来触发一个电话?

是否有一个特殊的URL,我可以输入像mailto:标签的电子邮件?

设备特定的解决方案不是首选。

我知道iPhone会自动识别电话号码,并为此创建一个链接,但如果这也能用于图像,那就太好了……大多数移动设备也是如此。


当前回答

正确的URL方案是[number],所以你会这样做

<a href="tel:5551234567"><img src="callme.jpg" alt="Call 5551234567" /></a>

其他回答

本质上,使用一个<a>元素,加上一个href attr,指向以tel:为前缀的电话号码。注意,加号可以用来指定国家代码,而连字符可以被简单地包括在人眼中。

MDN Web文档

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Creating_a_phone_link

HTML <a>元素(或锚元素),连同它的href属性,创建了一个指向其他网页、文件、同一页面中的位置、电子邮件地址或任何其他URL的超链接。 […] 提供电话链接有助于用户查看网络文档和连接到手机的笔记本电脑。 <a href="tel:+491570156">+49 1570156 </a>

IETF的文档

https://www.rfc-editor.org/rfc/rfc3966

The tel URI for Telephone Numbers The "tel" URI has the following syntax: telephone-uri = "tel:" telephone-subscriber […] Examples tel:+1-201-555-0123: This URI points to a phone number in the United States. The hyphens are included to make the number more human readable; they separate country, area code and subscriber number. tel:7042;phone-context=example.com: The URI describes a local phone number valid within the context "example.com". tel:863-1234;phone-context=+1-914-555: The URI describes a local phone number that is valid within a particular phone prefix.

正确的URL方案是[number],所以你会这样做

<a href="tel:5551234567"><img src="callme.jpg" alt="Call 5551234567" /></a>

只需使用HTML锚标记<a>和开始属性href tel:。我建议在电话号码前写上国家代码。请注意以下示例:

<a href="tel:+989123456789">NO Different What it is</a>

在本例中,国家代码是+98。

提示:它非常适合手机,我知道tel:前缀在macOS上呼叫FaceTime,但在Windows上我不确定,但我猜它导致了Skype的启动。

有关更多信息:您可以访问浏览器支持的URL方案列表,以了解所有href值前缀。

大多数现代设备都支持tel:方案。所以使用<a href="tel:555- 5555 -5555">555- 5555 -5555</a>,你应该可以开始了。

如果你想使用它的图像,<a>标签可以处理<img/>放置在它就像其他正常情况下:<a href="tel:555- 5555 -5555"><img src="path/to/phone/图标.jpg" alt="Call 555-5555 -5555" /></a>

在这个时候(2021年),要在PC或平板电脑和Android上工作(在IOS上没有测试,但应该可以工作),你需要在“a”标签中添加data-rel="external",示例:

<a href="tel:+576015000000" data-rel="external">Call Me...</a>