Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 http://whatsapp-sharing.com, 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.

like image 401
areim Avatar asked Jun 26 '15 09:06

areim


People also ask

How can I put WhatsApp Share button on my website?

This article describes how you can add WhatsApp share button in your website. Note: This will work only when website is open in mobile with WhatsApp installed. Step 1: Design a simple webpage with a hyperlink on it. Sharing will be done when user click on this link.

Where is the share icon on WhatsApp?

Click the | icon on the top left corner > Catalog. Select the product or service you wish to share. Click SHARE on the top right corner to.

How Share WhatsApp link in PHP?

To create your own link with a pre-filled message that will automatically appear in the text field of a chat, use https://wa.me/whatsappphonenumber/?text=urlencodedtext where whatsappphonenumber is a full phone number in international format and URL-encodedtext is the URL-encoded pre-filled message.


1 Answers

DEMO

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");
        }

    });
});

SOURCE

like image 178
Guruprasad J Rao Avatar answered Oct 20 '22 01:10

Guruprasad J Rao