Skip to content

Instantly share code, notes, and snippets.

@panayotoff
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panayotoff/78ade9d0da9ed2a96a32 to your computer and use it in GitHub Desktop.
Save panayotoff/78ade9d0da9ed2a96a32 to your computer and use it in GitHub Desktop.
Send SMS via JS
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SMS sender</title>
<style>
body {
font-family: Helvetica;
text-align: center;
}
.btn {
display: inline-block;
background-color: aquamarine;
color: black;
cursor: pointer;
padding: 20px 30px;
border-radius: 10px;
font-size: 22px;
}
.btn--send {
font-weight: bold;
margin: 50px auto;
}
</style>
</head>
<body>
<div id="send" class="btn btn--send">Send</div>
<script>
var $sendBtn = document.querySelector('#send'),
isAndroid = /Android/i.test(navigator.userAgent),
isIOS = /iPhone|iPad/i.test(navigator.userAgent);
var delim = isIOS ? '&' : '?',
phoneNumber = '0887666313',
message = 'SMS Body',
final = 'sms:' + phoneNumber + delim + 'body=' + encodeURIComponent(message);
$sendBtn.addEventListener('click', function () {
window.open(final, '_system');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment