I've found two ways to open the Whatsapp app from a webpage,
<a href="whatsapp://send?text=Hello&phone=+1123456789">whatsapp</a>
and
<a href="https://api.whatsapp.com/send?phone=+1123456789&text=Hello">whatsapp</a>
I understand the first one works on phone only but apart from that what are the differences between the two?
In my trials I've found that the api method doesn't always work properly in certain mobile browsers. In some cases it doesn't detect the installed app and takes me to the Appstore to install the app.
Does the first method work across all platforms and browsers?
Is it safe to use JavaScript to detect the platform (desktop or mobile) and then load the appropriate link format?
The first approach usually requires the browser / OS to understand how to handle the whatsapp:// protocol. This usually requires some setup beforehand (e.g. registering a protocol in Chrome, or a deep link schema in Android), and the browser / OS will pass the request to whatever app / program can handle it.
The second approach doesn't require any setup, and passes the request to WhatsApp's API directly. This is less likely to completely fail, but as you've seen may have issues on mobile when an app claims it should handle all requests to the domain.
You're better off following WhatsApp's documentation, and using their wa.me domain for a universal link:
Universal links can also include a pre-filled message that will automatically appear in the text field of a chat. Use
https://wa.me/whatsappphonenumber/?text=urlencodedtextwherewhatsappphonenumberis a full phone number in international format andurlencodedtextis the URL-encoded pre-filled message.Example:
https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
This will handle all the complexities for you. For example, on Android that URL opens the WhatsApp app, on Windows that universal link redirects to the api.whatsapp.com URL, and Chrome asks if I want to use my installed WhatsApp program for it:
