Skip to content

Instantly share code, notes, and snippets.

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 orpolaczek/fd1e7bfb3159881e45224c280445bcae to your computer and use it in GitHub Desktop.
Save orpolaczek/fd1e7bfb3159881e45224c280445bcae to your computer and use it in GitHub Desktop.
<script>
function cleanNumber(number) {
var cleanNum = (number || '' ).replace(/[^0-9]/g, "");
if (cleanNum[0] == '0') {
return "972" + cleanNum.substring(1);
} else {
return cleanNum;
}
}
function openWhatsapp() {
var number = document.getElementById("number").value;
document.location = "https://api.whatsapp.com/send?phone=" + cleanNumber(number);
}
</script>
<html>
<body>
<br/><br/>
<center>
<h2>Start a chat</h2>
<input type=text id="number"/><button onclick="openWhatsapp()">WhatsApp</button>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment