Bradorego's solution is what worked for me, but here is a more expanded answer.
A small consideration is that you need to encode the body using %20
instead of +
. For PHP, this means using rawurlencode($body)
instead of urlencode($body)
. Otherwise you'll see plus signs in the message on old versions of iOS, instead of spaces.
Here is a jQuery function which will refit your SMS links for iOS devices. Android/other devices should work normally and won't execute the code.
HTML:
<a href="sms:+15551231234?body=Hello%20World">SMS "Hello World" to 555-123-1234</a>
jQuery:
(function() {
if ( !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ) return;
jQuery('a[href^="sms:"]').attr('href', function() {
// Convert: sms:+000?body=example
// To iOS: sms:+000;body=example (semicolon, not question mark)
return jQuery(this).attr('href').replace(/sms:(\+?([0-9]*))?\?/, 'sms:$1;');
});
})();
Consider using a class like a.sms-link
instead of a[href^="sms:"]
if possible.