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.
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.
Share Improve this question edited Nov 18, 2014 at 11:52 Tomi Lammi asked Nov 18, 2014 at 11:42 Tomi LammiTomi Lammi 2,1261 gold badge18 silver badges12 bronze badges5 Answers
Reset to default 9100% 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
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
If you want to populate the body but not the phone number this works for both android and IOS8+
thisisthelink
the key is: "sms:?&"
you can open it with
window.open('sms:+1111111111')
it opens messaging app and ready to write something for that number
note:Tested in Android
It's not possible to add text, you can only add phone numbers so that
<a href="sms:+12345678901">sms link</a>
opens the messaging app.
Apps can register for custom protocol schemes to be called, when a request with such a url was made. But as far as I understand your solution is a pure web application, so the answer is no, it's not possible.