Javascript text a message rathen than email

All we need is an easy explanation of the problem, so here it is.

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>

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 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

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply