Last active
August 3, 2020 12:20
-
-
Save orpolaczek/fd1e7bfb3159881e45224c280445bcae to your computer and use it in GitHub Desktop.
This file contains 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
<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