Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening SMS editor from web application

I'm looking for a solution which allows me to open native SMS editor from web-page. Body of the message has to be prepopulated and receiver's phone number has to be empty.

There are plenty of suggestions here in stackoverflow to just format anchor or redirect via javascript but unfortunately these solutions are outdated and either do not work as is or are stripped for security reasons.

I've tested following formats on various platforms, but unfortunately they don't work on all devices. I'm looking for an universal solution or library to fulfill the requirements I mentioned.

<a href="sms:;body=Hello world">Send SMS</a>
<a href="sms:;body=Hello%20world">Send SMS</a>

Used to work on IOS devices but doesn't work anymore. Apparently pre-filled body only works if you supply a phone number which you have in your contacts.

<a href="sms:?body=Hello world">Send SMS</a>
<a href="sms:?body=Hello%20world">Send SMS</a>

Works on most android devices. Opens up SMS editor, but only some versions allow prepopulated body.

Windows Phone doesn't seem to do anything.

I'm starting to wonder if this is just an endless swamp of compability issues. Technology which the web application is built-on is ASP.NET MVC 5.

like image 529
Tomi Lammi Avatar asked Nov 18 '14 11:11

Tomi Lammi


People also ask

How do I open SMS app?

Open Settings . Click Apps. In the list of apps, click Messages. SMS.

How do I open messages on android?

From the Home screen, tap Messaging . The Messaging screen will open, where you can create a new message or open an ongoing message thread. Tap here to create a new message.


2 Answers

100% working

// for andriod

if(navigator.userAgent.match(/Android/i)){
            
    window.open('sms://1900/?body=encodeURIComponent('sms body......'),'_blank')
      
}

// for IOS

if(navigator.userAgent.match(/iPhone/i)){
           
 window.open('sms://1900/&body=encodeURIComponent('sms body......'),'_blank')
  
}

replace 1900 with the number you want to send message

Body = sms body

credit goes to :- https://codepen.io/gil--/pen/KMaRmp

like image 99
Rahul Singh Bhadhoriya Avatar answered Oct 04 '22 13:10

Rahul Singh Bhadhoriya


This works on iOS 8 (verified):

<p>Open <a href="#" id="myLink">SMS</a>.</p>
<script>
    $('#myLink').click(function () {
        window.open('sms:&body=My%20text%20for%20iOS%208', '_self');
        return false;
    });
</script>

This should works on iOS 5,6:

<p>Open <a href="#" id="myLink">SMS</a>.</p>
<script>
    $('#myLink').click(function () {
        window.open('sms:;body=My%20text%20for%20iOS%205', '_self');
        return false;
    });
</script>

Notice sms:& for iOS 8, sms:; for iOS 5,6 (and sms:? for Android).

Remember to encode the text after body=

Source: julianklotz

like image 44
Francesco Avatar answered Oct 04 '22 11:10

Francesco