javascript - WhatsApp share button on website. Easy way to detect if WhatsApp exists? -
i'm adding whatsapp share button on website , hide button when whatsapp functionality not exists (is not supported) on user device. there easy way? or way?
i found http://whatsapp-sharing.com, has disadvantages me. - no custom buttons/icons supported - looks it's detecting android , ios (what windows phone?) - hard maintain on bigger project
i'm searching js/jquery or maybe cssonly (mediaqueries?) solution, without success now. advice helpfull, thanks.
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 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 article in mobile device"); } }); });
Comments
Post a Comment