Web link to specific whatsapp contact

后端 未结 13 1886
青春惊慌失措
青春惊慌失措 2020-12-07 08:00

I\'d like to place a link on a webpage which opens a whatsapp chat with a certain whatsapp contact. In other words: I want a \"contact me by whatsapp\" link to go next to th

相关标签:
13条回答
  • 2020-12-07 08:36

    The solution that worked for me is here in PHP:

    $android = stripos($_SERVER['HTTP_USER_AGENT'], "android");
    $iphone = stripos($_SERVER['HTTP_USER_AGENT'], "iphone");
    $ipad = stripos($_SERVER['HTTP_USER_AGENT'], "ipad");
    
    $whatsappNumber = '1234597891';
    $whatsappLink = '';
    if($android !== false || $ipad !== false || $iphone !== false) {//For mobile
        $whatsappLink = '<a href="https://api.whatsapp.com/send?phone='.$whatsappNumber.'">'.$whatsappNumber.'</a>';
    } else {//For desktop
        $whatsappLink = '<a href="https://web.whatsapp.com/send?phone='.$whatsappNumber.'">'.$whatsappNumber.'</a>';
    }
    
    0 讨论(0)
  • 2020-12-07 08:38

    This answer is useful to them who want click to chat whatsapp in website to redirect web.whatsapp.com with default content or message and in mobile device to open in whatsapp in mobile app with default content to text bar in app.

    also add jquery link.

    <a  target="_blank" title="Contact Us On WhatsApp" href="https://web.whatsapp.com/send?phone=+919581880892&amp;text=Hi, I would like to get more information.." class="whatsapplink hidemobile" style="background-color:#2DC100">
        <i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
        <span style="color:#fff">
            Contact Us On WhatsApp        </span>
    </a>
    <a  target="_blank" title="Contact Us On WhatsApp" href="https://api.whatsapp.com/send?phone=+919581880892&text=Hi,%20I%20would%20like%20to%20get%20more%20information.." class="whatsapplink hideweb" style="background-color:#2DC100">
        <i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
        <span style="color:#fff">
            Contact Us On WhatsApp        </span>
    </a>
    
       <script type="text/javascript"> 
    var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) { 
    
        $('.hidemobile').css('display', 'none'); // OR you can use $('.hidemobile').hide();
    } 
    else 
    { 
        $('.hideweb').css('display', 'none'); // OR you can use $('.hideweb').hide();
    }
    </script>
    
    0 讨论(0)
  • 2020-12-07 08:40

    I tried all combination for swiss numbers on my webpage. Below my results:

    Doesn't work for Android and iOS

    https://wa.me/0790000000/?text=myText
    

    Works for iOS but doesn't work for Android

    https://wa.me/0041790000000/?text=myText
    https://wa.me/+41790000000/?text=myText
    

    Works for Android and iOS:

    https://wa.me/41790000000/?text=myText
    https://wa.me/041790000000/?text=myText
    

    Hope this information helps somebody!

    0 讨论(0)
  • 2020-12-07 08:41

    For what its worth, as of this writing (Nov. 29, 2018), the updated API that seems to work on my end is using this link:

    https://wa.me/<phone number here>
    

    Note:

    Just replace the placeholder <phone number here> with the intended phone number that you want to use INCLUDING the country code, this means I had to add +60 then the rest of the remaining number.

    It doesn't work on my end without one (using Android and iOS at least). It doesn't work means an error message that says along the lines of "you don't have this number".

    Reference:

    https://faq.whatsapp.com/en/general/26000030

    0 讨论(0)
  • 2020-12-07 08:42

    ********* UPDATE ADDED AT THE END *********

    I've tried many approaches and I have a winner (see Test 3), here is the result of each one:

    (I think the Test 3 will also work for you because if the person visiting your site doesn't have you on their contact list, it's the only option that will allow it.)

    In all tests, the number had to be complete, with country and location code without any initial zeros. Example:

    • +55(011) 99999-9999 (NOT)
    • +5511999999999 (YES)

    On tests 1 and 2, it only worked with a plus sign on the country code: +5511999999999

    Test 1:

    <a href="whatsapp://send?abid=phonenumber&text=Hello%2C%20World!">Send Message</a>
    

    This way you must have the phonenumber on your contact list. It doesn't work for me because I wanted to be able to send a message to a number which I may not have on my contact list.

    If you don't have the number on your contact list, it opens the Whatsapp listing all your registered contacts, so you can choose one.

    It's a good option for sharing stuff.

    Test 2:

    <a href="intent://send/phonenumber#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end">Send Message</a>
    

    This approach only works on Android AND if you have the number on your contact list. If you don't have it, Android opens your SMS app, so you can invite the contact to use Whatsapp.

    Test 3 (The Winner):

    <a href="https://api.whatsapp.com/send?phone=15551234567">Send Message</a>
    

    This was the only way that worked fully for me.

    • It works on Android, iOS and Web app on the desktop,
    • You can start a conversation with a number that you don't have on your contact list
    • You can create a link with one pre-built message adding &text=[message-url-encoded] like:

    https://api.whatsapp.com/send?phone=15551234567&text=Send20%a20%quote

    And if you wish to have a bookmarklet for additional ease of use, you may use this one:

    javascript: (function() { var val= prompt("Enter phone number",""); if (val) location="https://api.whatsapp.com/send?phone="+escape('972' + val)+""; })()

    Youll need to change the country code(or remove it) to you.r target country and paste it in the address field in a chrome/firefox link

    Worth notice:

    • I had to update my WhatsApp to the latest version
    • The number's country code must not have a leading plus
    • More details here: https://www.whatsapp.com/faq/en/general/26000030

    ***************** UPDATE (START) *****************

    Whatsapp made available other option, now you can create one link to a conversation like this:

    https://wa.me/[phonenumber]

    The phone number should be in international format:

    Like this:

    https://wa.me/552196312XXXX
    

    NOT like this:

    https://wa.me/+55(021)96312-XXXX
    

    And if you want to add one pre-built message to your link, you can add ?text= at the end with the text URL Encoded:

    https://wa.me/552196312XXXX?text=[message-url-encoded]
    

    Exemple:

    https://wa.me/552196312XXXX?text=Send20%a20%quote
    

    More info here:

    https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat

    ***************** UPDATE (END) *****************

    0 讨论(0)
  • 2020-12-07 08:43

    The following link seems to work fine -

    <a href="whatsapp://send?text=Hello World!&phone=+9198********1">Ping me on WhatsApp</a>
    

    It opens the contact in WhatsApp app, along with the message 'Hello World!' prepopulated in the input text box.

    (Tested this with google chrome on an android phone.)

    0 讨论(0)
提交回复
热议问题