huacnlee / social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
MIT License
582 stars 309 forks source link

WhatsApp Share Button #167

Closed NARKOZ closed 5 years ago

NARKOZ commented 6 years ago

Is it possible to add it?

huacnlee commented 5 years ago

https://github.com/huacnlee/social-share-button/pull/170 done

NARKOZ commented 5 years ago

Thanks.

StarWar commented 5 years ago

@huacnlee When using the WhatsApp as it's implemented, the snippet doesn't show and doesn't include the URL. I.e. You have to append the urlencoded URL to the text itself. Because including the URL as a query parameter doesn't work. I'm doing following work around:

//set up the url
        var url = "whatsapp://send?text=";
        //define the message text
        var title = $(document).find("title").text();
        var canonical = $("link[rel='canonical']").attr("href");
        var text = title + " at " + canonical;
        //encode the text
        var encodedText = encodeURIComponent(text);
        //set the href attribute on the link
        $whatsApp_app.attr("href", url + encodedText);