Html 如何让网站按钮打开短信组合成电话号码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30360701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make a website button open up an SMS compose to a phone number?
提问by Andrew
I've found solutions that make it so that when you click a button on a website, it links to a phone number and the users phone will open up the dialer with that number pre-filled like so.
我找到了这样的解决方案,当您单击网站上的按钮时,它会链接到一个电话号码,而用户的电话将打开拨号器,并像这样预先填充该号码。
What I want to do instead is open up the users sms application in "compose message" mode to that specific number. Is there any way to do this? I've tried the following approach, but it doesn't work on Android:
我想要做的是在“撰写消息”模式下打开用户短信应用程序到该特定号码。有没有办法做到这一点?我尝试了以下方法,但它不适用于 Android:
sms://1-516-400-6217
回答by Ashesh Kumar Singh
The general format is:
<a href="sms:+919999999999?body=Hello World!">Link</a>
一般格式为:
<a href="sms:+919999999999?body=Hello World!">Link</a>
You could also add multiple numbers to the recipient list:<a href="sms:+919999999999,+919999999990?body=Hello World!">Link</a>
您还可以向收件人列表添加多个号码:<a href="sms:+919999999999,+919999999990?body=Hello World!">Link</a>
I found this to be working on my Android device, as well:<a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a>
我发现这也适用于我的 Android 设备:<a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a>
A Small Demo:
一个小演示:
body {
font-family: monospace;
text-align: center;
}
a {
font-size: 24px;
}
code {
font-size: 18px;
line-height: 26px;
white-space: normal;
word-break: break-word;
background-color: lightgray;
padding: 5px;
border-radius: 4px;
}
h1 {
margin-bottom: 5%;
}
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1> Run this Snippet on an actual mobile device to check if it supports the special links</h1>
<hr>
<pre><code><a href="sms:+919999999999?body=Hello World!">Single recipient and plain body</a></code></pre>
<a href="sms:+919999999999?body=Hello World!">Single recipient and plain body</a>
<pre>
<br>
</pre>
<pre><code><a href="sms:+919999999999,+919999999990?body=Hello World!">Multile recipient and plain body</a></code></pre>
<a href="sms:+919999999999,+919999999990?body=Hello World!">Multile recipient and plain body</a>
<pre>
<br>
</pre>
<pre><code><a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a></code></pre>
<a href="sms://+919999999999?body=Hello%20World!">Single recipient and encoded body</a>
</body>
Source:Send a SMS Text From A Link
来源:从链接发送短信
As mentioned in the article the support depends on the platform and the SMS app, some work while others don't.
正如文章中提到的,支持取决于平台和 SMS 应用程序,有些有效,有些则无效。
Also avoid using it if there's no dynamic component involve for device detection; since on desktop the link will do absolutely nothing.
如果没有涉及设备检测的动态组件,也避免使用它;因为在桌面上,链接绝对不会做任何事情。