I'm trying to make a WhatsApp share option (for a mobile website) available to visitors that have the app installed.
What would be the best way to verify that the visitor is able to use this feature so I can enable/disable it accordingly?
The feature would just be a link using the custom URL scheme:
<a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>
You can solve this by checking whether the link will open or not.
Here is my code
function open_whatsapp(){
$.ajax({
type: 'HEAD',
url: 'whatsapp://send?text=Hello%20World!',
success: function() {
window.location='whatsapp://send?text=Hello%20World!';
},
error: function() {
alert("Whatsapp not installed");
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="share_whatsapp" onclick="open_whatsapp()">Share with Whatsapp</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With