【问题标题】:How to show an error message if viber sharing is not available?如果 viber 共享不可用,如何显示错误消息?
【发布时间】:2021-11-30 14:09:21
【问题描述】:

假设我在桌面上,或者在没有 Viber 应用程序的 Android 上。我按下它,没有任何反应。应该显示一条通知消息,例如“安装 Viber 应用程序!”或类似的东西。我只有这个:

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

我试过这些:

<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>

但它说“未安装”,无论是否安装。

【问题讨论】:

    标签: javascript share viber


    【解决方案1】:

    试试这个

      <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>
    

    有关更多信息,请参阅此 stackoverflow 帖子How to check app is installed or not using javascript

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2016-07-08
      • 1970-01-01
      相关资源
      最近更新 更多