That dude
That dude

Reputation: 389

How to share current URL using a WhatsApp share button

I have a blog app build on rails, i was searching on how to add a share button for WhatsApp, so that users can share the article they are reading with there contacts, i got something that worked in this answer.

According to the answer:

<a href="whatsapp://send?text=SHAREMESSAGE">Share on WhatsApp</a>

This worked but i want to share current URL when a user click the button.

Upvotes: 1

Views: 3974

Answers (2)

Muthu Kumar
Muthu Kumar

Reputation: 945

You can use basic DOM concept with JS to get the current URL, like:

var x = document.URL
window.location.href = "whatsapp://send?text="+x

Upvotes: 4

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33460

Use the Request#original_url:

<a href="whatsapp://send?text=<%= request.original_url %>">Share on WhatsApp</a>

Upvotes: 5

Related Questions