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.
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.
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.
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.
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
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