Craft SMS href links in Meteor (Both Android and iOS7)

To build links that trigger the mobile OS to create a text message, you would think it would be a simple matter…but it’s not. iOS and Android each have their own flavor. Andorid needs a “?” prefix to the body attribute, while iOS needs “;”. It’s not too difficult to have Meteor deliver the properly formatted link though.

We needed someone to TXT if the bus was late so in our HTML template, we desired the following output:

If the bus is late to start each day, TXT bus is late[sourcecode language=”js”] If the bus is late to start each day, TXT <a class="sendsms" href="#">bus is late</a> [/sourcecode]In your template events handler:[sourcecode language=”js”]{ ‘click a.sendsms’: function(event, template) { var telnumber = "sms:"+event.currentTarget.dataset.telnumber.toString(); var message = event.currentTarget.dataset.message; var sep = (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) ? ";body=" : "?body="; var link = telnumber + sep + encodeURIComponent(message); // console.log(link); location.href = link; } }); [/sourcecode]

Comments Closed.