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.
Open Settings . Click Apps. In the list of apps, click Messages. SMS.
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.
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
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With