Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a website button open up an SMS compose to a phone number?

Tags:

html

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:

sms://1-516-400-6217
like image 656
Andrew Avatar asked May 20 '15 21:05

Andrew


People also ask

How do I make a URL clickable in SMS?

There's just one easy step to follow. To include a link in any text message, just type or paste the full URL into your text. Most messaging platforms will automatically turn the URL into a link that allows contacts to click and access the linked page.


1 Answers

The general format is: <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>

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>

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>&lt;a href=&quot;sms:+919999999999?body=Hello World!&quot;&gt;Single recipient and plain body&lt;/a&gt;</code></pre>
  <a href="sms:+919999999999?body=Hello World!">Single recipient and plain body</a>

  <pre>
<br>
</pre>


  <pre><code>&lt;a href=&quot;sms:+919999999999,+919999999990?body=Hello World!&quot;&gt;Multile recipient and plain body&lt;/a&gt;</code></pre>
  <a href="sms:+919999999999,+919999999990?body=Hello World!">Multile recipient and plain body</a>

  <pre>
<br>
</pre>


  <pre><code>&lt;a href=&quot;sms://+919999999999?body=Hello%20World!&quot;&gt;Single recipient and encoded body&lt;/a&gt;</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.

Also avoid using it if there's no dynamic component involve for device detection; since on desktop older Operating Systems the link will do absolutely nothing.

like image 155
Ashesh Avatar answered Oct 02 '22 00:10

Ashesh