Using Android or a desktop browser, please visit this WhatsApp test page and click the Send
button. If WhatsApp is not installed it will show you a message.
How does the code detection on that page work? I tried the following but nothing happens.
try {
location.href = 'whatsapp://send/?phone=62812345678&text=test';
} catch (e) {
console.log(e);
}
Here my testing on Android:
Built-in Browser (Webview) and Firefox
if WA installed You can use iframe
to auto open WhatsApp
Chrome and Opera
Need user click action
and this simple code to check if WhatsApp are installed
let clickTimeout;
document.querySelector('#openWA').addEventListener('click', function() {
let start = Date.now();
clickTimeout = setTimeout(function() {
if (Date.now() - start > 1250)
return;
alert('WA not installed')
}, 1e3);
// reset the setTimeout or the alert will always be fired
window.addEventListener("blur", function() {
clearTimeout(clickTimeout)
});
})
<a href="whatsapp://send/?phone=62812345678&text=test" id="openWA">Send to WhatsApp</button>
<!-- Auto open on WebView and Firefox -->
<iframe id="launcher" src="whatsapp://send/?phone=62812345678&text=test" style="display: none;"></iframe>