Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share via WhatsApp only if it is installed

I'm trying to make a WhatsApp share option (for a mobile website) available to visitors that have the app installed.

What would be the best way to verify that the visitor is able to use this feature so I can enable/disable it accordingly?

The feature would just be a link using the custom URL scheme:

<a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>

like image 991
Jamie Kudla Avatar asked Dec 05 '14 17:12

Jamie Kudla


1 Answers

You can solve this by checking whether the link will open or not.

Here is my code

function open_whatsapp(){
    $.ajax({
      type: 'HEAD',
      url: 'whatsapp://send?text=Hello%20World!',
      success: function() {
        window.location='whatsapp://send?text=Hello%20World!';   
      },
      error: function() {
        alert("Whatsapp not installed");
      }
    });
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="share_whatsapp" onclick="open_whatsapp()">Share with Whatsapp</button>
like image 185
Sree KS Avatar answered Nov 08 '22 16:11

Sree KS