/    Sign up×
Community /Pin to ProfileBookmark

Inserting Whatsapp into a website using Javascript.

Hi guys,

While building my new DJ-Website, I had some problems with this :

I would like to make an icon, which only appears while being on a smartphone (android or iphone).

When this is detected, I’d like to make this icon create a whatsapp chat with me.

This is what the android code looks like :

<li><a href=”intent://send[B]/PHONE NUMBER[/B]#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end” class=”fa fa-whatsapp”><span class=”label”>Whatsapp</span></a></li>

This code turned out to work perfectly, so that isn’t a problem anymore.

[B]Where I need your help for :[/B]

[LIST]

  • [*]

    Making the code above only pop-up when using android


  • [*]

    A code to get the same result, but now for iphone’s.


  • [/LIST]

    Thanks in advance! I already appreciate your help ?

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @r8rMar 31.2015 — Ad a.) see http://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery on how to use jQuery to detect android devices. Although, you can parse the user agent string on the server side also.

    ad b.) I wouldn't be surprised if this isn't possible. Take a look at this maybe: http://whatsapp-sharing.com


    All retrieved within couple of minutes using Google.
    Copy linkTweet thisAlerts:
    @bartduisauthorMar 31.2015 — Thanks for the reply! I used that code, but unfortunately, it didn't work.

    It turned out to depend on another part of the code..

    This is my final (working ?) code :

    <div class="hidden" id="id1"><li><a href="intent://send/[I][B]PHONE_NUMBER[/B][/I]#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end" class="fa fa-whatsapp"><span class="label">Whatsapp</span></a></li> </div>

    <script>


    document.getElementById("id1").style.visibility = "hidden";

    var ua = navigator.userAgent.toLowerCase();

    var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

    if(isAndroid) {

    document.getElementById("id1").style.visibility = "visible";



    }

    </script>
    ×

    Success!

    Help @bartduis spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...