1

Say, I'm on desktop, or on Android which has no Viber application. I press it and nothing happens. A notice message ought to be shown, like "Install the Viber application!" or something like that. All I have is this:

<a href="viber://forward?text=text">Click here to share!</a>

I tried these:

<a href="whatsapp://send/?phone=62812345678&amp;text=test" id="openWA">Send to WhatsApp</a>
<br>
<a href="viber://forward?text=paff" id="openV">Send to Viber</a>

<!-- Auto open on WebView and Firefox -->

<script>
    document.querySelector('#openWA').addEventListener('click', function() {
        var f = Date.now(),
            j = setTimeout(function() {
                if (Date.now() - f > 1250)
                    return;
                alert('WA not installed')
            }, 1e3);
    });
    document.querySelector('#openV').addEventListener('click', function() {
        var f = Date.now(),
            j = setTimeout(function() {
                if (Date.now() - f > 1250)
                    return;
                alert('VIBER not installed')
            }, 1e3);
    });
</script>

but it say "not installed", either it is or not.

Neptotech -vishnu
  • 1,096
  • 8
  • 23
John Smith
  • 6,129
  • 12
  • 68
  • 123

1 Answers1

1

Try using this

  <a href="#" id="openWA">Send to WhatsApp</a>
<br>
<a href="#" id="openV">Send to Viber</a>

<!-- Auto open on WebView and Firefox -->

<script>
    document.querySelector('#openWA').addEventListener('click', function() {
      setTimeout(() =>{
        alert("Whatsapp not installed")
      }, 500)
      window.location.replace('whatsapp://send/?phone=62812345678&amp;text=test')
            
    });
    document.querySelector('#openV').addEventListener('click', function() {
      setTimeout(() =>{
        alert("Viber not installed")
      }, 500)
      window.location.replace('viber://forward?text=paff')
            
    });
</script>

For more information see this stackoverflow post How to check app is installed or not using javascript

Gahan Vig
  • 196
  • 2
  • 13