仅在已安装的情况下通过 WhatsApp 共享 [英] Share via WhatsApp only if it is installed

查看:33
本文介绍了仅在已安装的情况下通过 WhatsApp 共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为安装了该应用的访问者提供一个 WhatsApp 共享选项(适用于移动网站).

I'm trying to make a WhatsApp share option (for a mobile website) available to visitors that have the app installed.

验证访问者是否能够使用此功能以便我可以相应地启用/禁用它的最佳方法是什么?

What would be the best way to verify that the visitor is able to use this feature so I can enable/disable it accordingly?

该功能只是使用自定义 URL 方案的链接:

The feature would just be a link using the custom URL scheme:

<a href="whatsapp://send?text=Hello%20World!">你好,世界!</a>

推荐答案

您可以通过检查链接是否打开来解决此问题.

You can solve this by checking whether the link will open or not.

这是我的代码

function open_whatsapp(){
    $.ajax({
      type: 'HEAD',
      url: 'whatsapp://send?text=Hello%20World!',
      success: function() {
        window.location='whatsapp://send?text=Hello%20World!';   
      },
      error: function() {
        alert("Whatsapp not installed");
      }
    });
  }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="share_whatsapp" onclick="open_whatsapp()">Share with Whatsapp</button>

这篇关于仅在已安装的情况下通过 WhatsApp 共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆