I want to enable my website users to share the current web page url (stored in ViewBag.OgUrl) via WhatsApp.
The WhatsApp message should contain the url title (stored in ViewBag.OgTitle) which, when clicked, will open the url (stored in ViewBag.OgUrl).
This needs to be done by html without js.
The standard way is:
@{
var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgUrl;
}
And then simply:
<a href="@urlWhatsapp" target="_blank">WhatsApp Share</a>
This works fine apart from the fact that the actual url is shared and not the title.
For example, a WhatsApp message contains the actual link http://example.org/ while I would like it to show in WhatsApp:
First example
Edit: If one wants to get the title and the link just replace the code with:
@{var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgTitle + " - " + @ViewBag.OgUrl;}
<a class="fa fa-whatsapp" href="@urlWhatsapp" target="_blank"></a>
If one waits after the sharing, but before actually sending the message to the recipient, a clickable box appears above the original message (as would be for any whatsapp link with what is defined in the url - an image, text etc. according - see the example below)
It is not possible to share a link on WhatsApp the way you want to. You can only send a message with the full link like http://example.org/
and WhatsApp will detect this as a link for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With