Link to chat whatsapp desktop

Viewed 26051

Is it possible to create link to chat for whatsapp on desktop and specify number which doesn't exist in contact list?

<a href="whatsapp://send?phone=phoneNumber=">whatsapp</a>

This implementation works fine for mobile(doesn't matter number exists in your contact list or not), but for desktop in doesn't work if there are no such contact in your contact list and as a result I got a pop-up window with message 'Phone number shared via url is invalid'

6 Answers

Try this:

<body class="" onload="myWhatsappFunction()">

  <a id="whatsapp-btn" class="" target="_blank"> Whatsapp</a>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.4.3/mobile-detect.min.js"></script>

  <script>
    var whatsapp_number = YOUR_PHONE_NUMBER_HERE;

    function myWhatsappFunction() {
      var md = new MobileDetect(window.navigator.userAgent);
      if (md.mobile()) {
        // mobile link
        document.getElementById("whatsapp-btn").href = "https://wa.me/" + whatsapp_number;
      } else {
        // desktop link
        document.getElementById("whatsapp-btn").href = "https://web.whatsapp.com/send?phone=" + whatsapp_number;
      }
    };
  </script>

References:

A possible cause of this error 'Phone number shared via URL is invalid' is that the phone number that you are trying to invoke is not on Whatsapp list, i.e. the number does not receive WhatsApp messages since it might not be registered on WhatsApp. I tried that using several of my phone numbers and the ones not on WhatsApp were throwing this error but those on WhatsApp worked. Guess will save someone from debugging.

To create your own link to your whatsapp number with a pre-filled message that will automatically appear in the text field of a Whatsapp WEB-chat, you can use: (Dont work on Firefox web browser)

<a href="https://api.whatsapp.com/send?phone=yourwhatsappnumberwithcountrycode&text=hello"</a>

this API promises work on all browsers check it out: https://www.forblink.com/

A very simple solution. I added my country's area code (+44) in-front of the mobile number.

It works for both mobile and desktop.

Related