Last active
January 18, 2018 14:57
-
-
Save julianklotz/7b2f98b77a171d2d32b3 to your computer and use it in GitHub Desktop.
Utility functions for linking into native messaging applications (currently SMS and WhatsApp) without prepoluating a phone number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Utility functions for linking into native messaging applications (currently SMS and WhatsApp) without prepoluating a phone number. | |
* | |
* Plinks is based on this blog post I wrote earlier this year: | |
* http://blog.julianklotz.de/2015/03/14/the-sms-uri-scheme/ | |
* | |
* MIT license. | |
*/ | |
window.plinks = (function() { | |
'use strict'; | |
var exports = {}; | |
var isIosDevice = (function() { | |
var ua = navigator.userAgent.toLowerCase(); | |
if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) { | |
return true; | |
} else { | |
return false; | |
} | |
})(); | |
/** | |
* Call plinks.smsLink('myMessage') to get a proper SMS link href | |
* The phone number cannot be pre-populated. | |
*/ | |
exports.smsLink = function(message) { | |
var msg = encodeURIComponent(message), href; | |
// No more support for iOS 6 + 7 | |
if(isIosDevice) { | |
href = "sms:&body=" + msg; | |
} else { | |
href = "sms:?body=" + msg; | |
} | |
return href | |
}; | |
exports.whatsAppLink = function(message) { | |
var msg = encodeURIComponent(message), href; | |
href = "whatsapp://send?text=" + msg; | |
return href | |
} | |
return exports | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fantastic. Is this up to date?