areim areim - 1 year ago 106
CSS Question

WhatsApp share button on website. Easy way to detect if WhatsApp exists?

I'm adding WhatsApp share button on my website and I would like to hide this button when WhatsApp functionality does not exists (is not supported) on user device. Is there an easy way? Or any way?

I found, but it has some disadvantages for me.
- no custom buttons/icons supported
- looks like it's detecting only Android and IOs (what about Windows Phone?)
- hard to maintain on bigger project

I'm searching for some JS/jQuery or maybe CSSonly (mediaqueries?) solution, but without success for now.
Any advice would be helpfull, thanks.

Answer Source


Try this

$(document).ready(function() {

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
if( isMobile.any() ) {
    //hide the share button
 $(document).on("click", '.whatsapp', function() {
        if( isMobile.any() ) {
            var text = $(this).attr("data-text");
            var url = $(this).attr("data-link");
            var message = encodeURIComponent(text) + " - " + encodeURIComponent(url);
            var whatsapp_url = "whatsapp://send?text=" + message;
            window.location.href = whatsapp_url;
        } else {
            alert("Please share this article in mobile device");



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download