6

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) enter image description here

user6099216
  • 95
  • 1
  • 1
  • 8

4 Answers4

4

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.

1

the question asked about an html based procedure (no js)

The answer is that at this time, it is possible to send text + a link to be identified by WhatsApp.

it is not possible to send only a title which, when clicked, will be linked to the url itself.

The syntax in the html is:

    @{var urlWhatsapp = "whatsapp://send?text=" + @ViewBag.OgTitle + " - " + @ViewBag.OgUrl;}

    <a class="fa fa-whatsapp" href="@urlWhatsapp" target="_blank"></a>

where the @ViewBag.OgTitle is the title and the @ViewBag.OgUrl is the full url (including http:// or https://)

user6099216
  • 95
  • 1
  • 1
  • 8
  • 1
    How to create a message in whatsapp with a hyperlink in it. I want to give a name to hyperlink. I receive such messages via whatsapp. – Davoud May 24 '18 at 07:27
  • I have edited the answer to the best analog I am aware of. If you apply this, and wait for a second or two after the sharing you will get above the original text with the link the description + some photo (if you applied it) and this is clickable to get to your link – user6099216 Aug 07 '18 at 04:18
0

Try:

<a href="https://web.whatsapp.com/send?l=en&phone=+91 0000000000&text=I want to 
order a website" target="blank"></a>

Where 0000000000 will be your 10 digit mobile no. and text= will be your predefined message.

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
0

You have two options to send messages to Whatsapp from a link on your site.

The first one...

<a href="https://wa.me/5579XXXXXXXXX"><i class="fab fa-whatsapp"></i> +55 (79) XXXXX-XXXX</a>

The second, with predefined text...

<a href="https://wa.me/5579XXXXXXXXX?text=I'm%20interested%20to%20know%20more%20about%20your%20job."><i class="fab fa-whatsapp"></i> +55 (79) XXXXX-XXXX</a>
  • You don't need to put "+" (plus) in your number.
  • To do spaces in the text, you need to use "%20" between words.