2014-12-05 54 views
4

我正在嘗試爲安裝了該應用程序的訪問者提供WhatsApp共享選項(針對移動網站)。只有在安裝時才通過WhatsApp共享

驗證訪問者能夠使用此功能的最佳方式是什麼,以便我可以相應地啓用/禁用它?

的功能也只是使用自定義URL方案的鏈接:

<a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>

+0

你能解決這個問題呢? – 2015-07-06 06:57:50

回答

3

您可以通過檢查鏈接是否會打開或不解決這個問題。

這裏是我的代碼

<a id="share_whatsapp" onclick="open_whatsapp()">Share with Whatsapp</a> 
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js?ver=4.1' type='text/javascript'></script> 
<script> 
    function open_whatsapp(){ 
    $.ajax({ 
     type: 'HEAD', 
     url: 'whatsapp://send?text=text=Hello%20World!', 
     success: function() { 
     window.location='whatsapp://send?text=text=Hello%20World!'; 
     }, 
     error: function() { 
     alert("Whatspp not installed"); 
     } 
    });  
    } 
</script> 
0

這不是很好的解決方案,因爲它依賴於OS。

if(isMobile()){ 
    function onWhatsAppClick(e){ 
     e.preventDefault(); 
     window.location='whatsapp://send?text=text=Hello%20World!'; 
    } 
} 

解釋:

  1. 您應該檢查並顯示WhatsApp的隻手機。
  2. 防止默認,並打開window.location的

Plunker鏈接:https://plnkr.co/edit/U4CtbxeA81d25lc7dlGe?p=preview