jQuery code to share content on whatsapp

In this short post, find jQuery code to share any content on whatsapp. The code first checks for mobile device and if it's a mobile device then it just creates whatsapp URL with user defined text and link to share and then just redirects it. That's it.

jQuery code to share content on whatsapp
$(document).ready(function () {
   $(document).on("click", '.whatsapp', function () {
      if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
        var sText = "Text to share"; 
        var sUrl = "Link to share";
        var sMsg = encodeURIComponent(sText) + " - " + encodeURIComponent(sUrl);
        var whatsapp_url = "whatsapp://send?text=" + sMsg;
        window.location.href = whatsapp_url;
     } 
     else {
        alert("Whatsapp client not available.");
     }
  });
});

You may also like:

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...