0

I'm looking for a way to use JavaScript to open texts on ios or android when a link is clicked. Currently, you can use the mailto links in HTML to mail a link and open the link in an empty email. I'm wondering how I can do the same using text. For example, a user clicks and button and it will open the messages app and auto-fill with some information similar to the mailto only for messages. How can this be done?

Current code:

<button onclick="text()">text message</button>
<script>
 function text() {
  //Code for text messages
 }
</script>
Heartbit
  • 1,698
  • 2
  • 14
  • 26
Aidan Young
  • 554
  • 4
  • 15
  • You can try this: [SMS URL on Android](https://stackoverflow.com/questions/4787905/sms-url-on-android) – Rida Dec 17 '21 at 23:36
  • The issue with this is it only works in android, I’m looking for a iOS and Android solution – Aidan Young Dec 17 '21 at 23:41

1 Answers1

1

sms: works for both ios and android.

For ios:

The sms scheme is used to launch the Messages app. The format for URLs of this type is “sms:”, where is an optional parameter that specifies the target phone number of the SMS message. This parameter can contain the digits 0 through 9 and the plus (+), hyphen (-), and period (.) characters. The URL string must not include any message text or other information.

The following examples show strings formatted for Safari and for native apps.

HTML links:

<a href="SMS:"> Launch Messages App</a> <a href="sms:1-408-555-1212">New SMS Message</a>

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html

Rida
  • 131
  • 5
  • Not sure if it's because I'm not an older device but the link didn't go anywhere when I tried to access it on my phone. Does it work on older ios or android devices? – Aidan Young Dec 18 '21 at 00:17