275

I have developed a website which is mainly used in mobile phones.
I want to allow users to share information directly from the web page into WhatsApp.

Using UserAgent detection I can distinguish between Android and iOS.
I was able to discover that in order to implement the above in iOS I can use the URL:

href="whatsapp://send?text=http://www.example.com"

I'm still looking for the solution to be used when the OS is Android (as the above doesn't work).
I guess it is somehow related to using "intent" in Android, but I couldn't figure out how to do it as parameter for href.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Yochai
  • 2,783
  • 2
  • 12
  • 8
  • This way connects to the Whatsapp app, and there's another way to connect to the web.whatsapp.com option. Is there any way that would detect if you have the app or not, to see which to connect to? – SrQ Jan 04 '19 at 19:29
  • 1
    Which contact will receive this message? – Codebeat Jul 24 '19 at 01:51

16 Answers16

380

Just saw it on a website and seems to work on latest Android with latest chrome and whatsapp now too! Give the link a new shot!

<a href="whatsapp://send?text=The text to share!" data-action="share/whatsapp/share">Share via Whatsapp</a>

Rechecked it today (17th April 2015):
Works for me on iOS 8 (iPhone 6, latest versions) Android 5 (Nexus 5, latest versions).

It also works on Windows Phone.

Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72
Manuel
  • 9,112
  • 13
  • 70
  • 110
  • 1
    indeed it seems that the original URL in my question also works now for Android. – Yochai Oct 11 '14 at 22:15
  • Whoever upvoted @MosheL's undoubtedly insightful comment must have intimate knowledge of what exactly his "item" is. – Dan Dascalescu Jul 11 '15 at 04:26
  • 10
    @Manuel what is data-action="share/whatsapp/share" for? – user3362364 Jul 28 '15 at 07:43
  • No, as far as I'm concerned I think it is not necessary. In the beginning, than it only worked on ios, i used it for styling and hidding on desktop and android. Now I only use it for google analytics tracking as category action lable – Manuel Aug 07 '15 at 09:22
  • 4
    The Data should be in url encoded form.otherwise it will send blank message in whatsapp iphone. – Lijo Abraham Nov 20 '15 at 10:21
  • what about starting a chat with a specific number? sort of like the `tel:+12345678` format. is there a more complete docs on this? – RZKY Dec 13 '15 at 18:42
  • as far as I know not. The only offical docu I know is https://www.whatsapp.com/faq/en/android/28000012 just giving the link above. As of F8 developer conference no api is planned by whatsapp http://mashable.com/2015/03/25/whatsapp-developers-api/#n7c9guyx8Sqr – Manuel Dec 22 '15 at 08:19
  • @RZKY Neither of the third party apis I know support has such a feature either. Moreover according some forums they chase against marketing automation through those reverse engineered apis and their abuse with eg. https://github.com/WHAnonymous/Chat-API. However I think your idea is pretty smart, makeing a contact me whatsapp button. Maybe it is possible to request such a feature on whatsapp? – Manuel Dec 22 '15 at 08:40
  • when I tried to post a https link via WhatsApp it throws me this message and not able to open WhatsApp Navigation is unreachable: unsafe:whatsapp://send?text=https://qa.xxxxxx.com/xxxxx trying with ionic framework – user3625547 Mar 21 '16 at 10:42
  • This worked for me on iOS Safari but not iOS chrome. Any one else have this issue? Chrome opened WhatsApp but the message was blank. Safari had it perfect. – Peege151 Apr 10 '16 at 19:49
  • "This feature is not supported. Please stop using it." ~ support.whatsapp.com – HoldOffHunger Mar 28 '18 at 13:13
  • 1
    Some API changes can be found in recent document - https://faq.whatsapp.com/en/general/26000030/?category=5245251 – abhishek77in Jun 21 '18 at 11:14
135

The above answers are bit outdated. Although those method work, but by using below method, you can share any text to a predefined number. The below method works for android, WhatsApp web, IOS etc.

You just need to use this format:

<a href="https://api.whatsapp.com/send?phone=whatsappphonenumber&text=urlencodedtext"></a>

UPDATE-- Use this from now(Nov-2018)

<a href="https://wa.me/whatsappphonenumber/?text=urlencodedtext"></a>

Use: https://wa.me/15551234567

Don't use: https://wa.me/+001-(555)1234567

To create your own link with a pre-filled message that will automatically appear in the text field of a chat, use https://wa.me/whatsappphonenumber/?text=urlencodedtext where whatsappphonenumber is a full phone number in international format and URL-encodedtext is the URL-encoded pre-filled message.

Example:https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale

To create a link with just a pre-filled message, use https://wa.me/?text=urlencodedtext

Example:https://wa.me/?text=I'm%20inquiring%20about%20the%20apartment%20listing

After clicking on the link, you will be shown a list of contacts you can send your message to.

For more information, see https://www.whatsapp.com/faq/en/general/26000030

ad08
  • 2,522
  • 1
  • 14
  • 18
  • 2
    I tested this in all devices. All it does is open the whatsapp application. Nothing happens afteward. Tested multiple devices (iOS, Android, Windows). – HoldOffHunger Mar 27 '18 at 13:11
  • @HoldOffHunger yes it will open whatsapp application and the user have to select the contact to which he desires to share the link/content. – ad08 Apr 04 '18 at 12:25
  • @ad08: That is how Threema and the other 40 services I tested worked. Viber and WhatsApp, however, do nothing, I contacted their developers, and they both admitted the API does nothing. I've kept track of their correspondence and the other 40 api's (which work) here: https://github.com/bradvin/social-share-urls/blob/master/README.md – HoldOffHunger Apr 04 '18 at 12:30
  • Works on WhatsApp Desktop under Mojave – Alchem Feb 26 '19 at 08:03
  • 8
    wa.me links doesn't work properly on mobile without a phone number. Even though the official documentation states that you can use it, it just gives an error. It does work in desktop, using WhatsApp web. api.whatsapp.com works reliably on both. – Ricardo Gonçalves Jul 16 '19 at 00:57
  • If you want to use WhatsApp share in browser (not mobile) and don't have WhatsApp installed, you can append app_absent=1 in your url query parameter, so that WhatsApp will show option to open WhatsApp Web. For example: [https://wa.me/whatsappphonenumber/?text=urlencodedtext&app_absent=1](https://wa.me/whatsappphonenumber/?text=urlencodedtext&app_absent=1) – pijushbarik Feb 06 '21 at 07:43
47

Currently, it's very easy to achieve this. You only need to add the following code to your pages:

<a href="whatsapp://send?text=<<HERE GOES THE URL ENCODED TEXT YOU WANT TO SHARE>>" data-action="share/whatsapp/share">Share via Whatsapp</a>

And that's it. No Javascript needed, nothing else needed. Of course you can style it as you want and include a nice Whatsapp icon.

I tested this in my Android device with Google Chrome. The versions:

  • Android 4.1.2 (Jelly Bean)
  • Chrome Mobile 37.0.2062.117. Also tested on Firefox Mobile 31.0.
  • Whatsapp V 2.11.399

It also works on iOS. I've made a quick test on an iPhone 5 with Safari and it works as well.

Hope this helps someone. :-)

juangalf
  • 832
  • 1
  • 10
  • 17
  • 3
    For encode your content to share use `encodeURIComponent()` – nikoskip Nov 26 '14 at 19:05
  • 1
    hey, that worked for me. thanks :) Just curious, if there's way if I can check whether user actually shared the link or simply came back to site? – Sayed Nov 27 '14 at 13:01
  • 1
    Works also on my Nexus 5 with Android 5.0 (Lollipop), and iPhone 5 with iOS 8.1.1. – Narxx Nov 30 '14 at 10:09
  • 2
    @juangalf What if I want to share an image using this method? will that be possible too, or only text supported? – elembivos Feb 25 '15 at 13:23
  • 1
    @elembivos I'm asking the same. How does the `send` parameter have to be formated? Currently, I have `whatsapp://send?text=data:image/png;base64,iVBORw0KGgoAAAANS...` but not sure how much of the prefixes to include... – TMOTTM Aug 27 '17 at 09:48
  • 1
    @juangalf What do you mean `you can style it as you want`? – TMOTTM Aug 28 '17 at 20:47
  • @TMOTTM: You can style the link with CSS to fit your needs. For example, the last time I implemented this link, I added a green background with the WhatsApp logo on it using the css property "background". Regarding the question about the image (also asked by @elembivos) I'm not sure how to do it, but it seems it has to be done by using og tags. This is a thread that may help you: https://stackoverflow.com/questions/44501902/share-image-content-and-url-on-whatsapp-from-web-site-without-og-tag. – juangalf Sep 10 '17 at 15:58
45

According to the new documentation, the link is now:

<a href="https://wa.me/?text=urlencodedtext">Share this</a>

If it doesn't work, try this one :

<a href="whatsapp://send?text=urlencodedtext">Share this</a>
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84
  • 3
    So it's also possible without a phone number. This doc can be found here: https://faq.whatsapp.com/en/general/26000030 – Tim Vermaelen Oct 22 '18 at 10:03
  • 2
    I have just discovered it is not working properly anymore. It just works with phone number. Without a phone number you need to use api.whatsapp.com – Ricardo Gonçalves Jul 16 '19 at 00:58
  • @RicardoBRGWeb sure of this ? I just tried on my web browsers, works for me without any number, it purposes me the Web Whatsapp interface and to share to a contact – Vincent Decaux Aug 13 '19 at 17:48
  • @VincentDecaux it works in desktop browsers, even when using the mobile view mode. But it won`t work in mobile browsers to open whatsapp or whatsapp business apps. Probably they have changed the internal linking uri in the app. – Ricardo Gonçalves Aug 21 '19 at 15:21
  • Ok, did you try my 2nd option ? fairly I didn't try on mobile brower, I will try tomorrow – Vincent Decaux Aug 21 '19 at 19:29
  • Ok, did you try my 2nd option ? fairly I didn't try on mobile brower, I will try tomorrow – Vincent Decaux Aug 21 '19 at 19:29
36

The official docs say to use: wa.me. Don't use wa.me. I apologize for the length of these results, but it's been a rapidly-evolving issue....

April, 2020 Results

Share Link

This link is incorrect. Close this window and try a different link.

May, 2020 Results

Share Link GitHub Ticket: WhatsApp short link without phone number not working anymore

We couldn't find the page you were looking for

Looks like you're looking for a page that doesn't exist. Or a page we might have just deleted. Either way, go back or be sure to check the url, your spelling and try again.

August, 2020 Results

Share Link

Works as expected!

LATEST - October, 2020 Results

Share Link

(Broken again!) og:image tag previews are disabled when using wa.me.

Based on some of the comments I'm seeing, it seems like this still be an intermittent problem, so, going forward, I recommend you stick to the api.whatsapp.com URL!

If you want to share, you must absolutely use one of the two following URL formats:

https://api.whatsapp.com/send?text=YourShareTextHere
https://api.whatsapp.com/send?text=YourShareTextHere&phone=123

If you are interested in watching a project that keeps track of these URLs, then check us out!: https://github.com/bradvin/social-share-urls#whatsapp

Social Share URLs

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
  • Using `whatsapp://send?text=` does work for me, with or without URL encode. Only tested it on iOS – Snowball Jun 14 '18 at 08:58
  • Hey, @Snowball: Thanks for the comment, actually, that'll only work when the whatsapp app is installed. That's normal for `customProtocol://action=?` types of links. So, that'll do nothing on a desktop. Using that would require detecting the OS, then using one URL for desktop, and another for iOS. But that's really a different matter altogether than what the OP is asking. – HoldOffHunger Jun 18 '20 at 18:39
  • 1
    This is the best solution if you wish to include an OpenGraph image (og:image) in the sharing. – Marcio Duarte Aug 21 '20 at 16:49
  • @HoldOffHunger how can we share images with this api.whatsapp link? – Developer Nov 03 '20 at 20:39
  • @GuarangDhorda: use the `og:image` tag. – HoldOffHunger Nov 03 '20 at 22:16
  • @HoldOffHunger is it also possible to share dynamic meta image changing with url params. the above solution doesnt work for this case. – Mudit Sharma Oct 03 '21 at 07:52
14

Recently WhatsApp updated on its official website that we need to use this HTML tag in order to make it shareable to mobile sites:

<a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>

You can replace text= to have your link or any text content

jou
  • 5,824
  • 3
  • 22
  • 24
Aadil Keshwani
  • 1,385
  • 1
  • 18
  • 29
12

LATEST UPDATE

Now you can use the latest API from whatsapp https://wa.me/ without worrying about the user agent, the API will do the user agent handling.

Share pre-filled text with contact selection option in respective whatsapp client (Android / iOS / Webapp):

https://wa.me/?text=urlencodedtext

Open Chat Dialog for a particular whatsapp user in respective whatsapp client (Android / iOS / Webapp):

https://wa.me/whatsappphonenumber

Share pre-filled text with a particular user (Combine above two):

https://wa.me/whatsappphonenumber/?text=urlencodedtext

Note : whatsappphonenumber should be full phone number in international format. Omit any zeroes, brackets or dashes when adding the phone number in international format.

For official documentation visit https://faq.whatsapp.com/en/general/26000030

Shri
  • 938
  • 1
  • 11
  • 19
  • 1
    https://wa.me/whatsappphonenumber/?text=urlencodedtext is not working it seems – Kiran Jun 18 '20 at 18:28
  • @Kiran You need to replace `whatsappphonenumber` with the full phone number in international format e.g. 919999999999 – Shri Jul 12 '20 at 20:16
7

I'm afraid that WhatsApp for Android does not currently support to be called from a web browser.

I had the same requirement for my current project, and since I couldn't find any proper information I ended up downloading the APK file.

In Android, if an application wants to be called from a web browser, it needs to define an Activity with the category android.intent.category.BROWSABLE.

You can find more information about this here: https://developers.google.com/chrome/mobile/docs/intents

If you take a look to the WhatsApp AndroidManifest.xml file, the only Activiy with category BROWSABLE is this one:

<activity android:name="com.whatsapp.Conversation"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="stateUnchanged">
        <intent-filter>
            <action android:name="android.intent.action.SENDTO" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="sms" />
            <data android:scheme="smsto" />
        </intent-filter>
    </activity>

I've been playing with it for a while, and I couldn't make it to work. The most I got was to open the WhatsApp application from Chrome, but I couldn't figure out a way to set the message content and recipient.

Since it is not documented by the WhatsApp team, I think this is still work in progress. It looks like in the future WhatsApp will handle SMS too.

The only way to get more information is by reaching the WhatsApp dev team, what I tried, but I'm still waiting for a response.

Regards!

oliferna
  • 369
  • 1
  • 3
  • 9
  • 1
    Can I ask you to share any new information about this issue here? Would be very convenient for me too. Anyway, thank you for the exhaustive answer. – ccalboni Jun 11 '14 at 14:44
  • I was able to get in contact with the WhatsApp devs. They admitted this feature is not supported. – HoldOffHunger Mar 28 '18 at 13:13
7

Just tested the whatsapp:// scheme on my super old Android 2.3.3 with Whats App 2.11.301, works like a charm. It seems to be just the Whats App version. Since Whats App is forcing everyone to update, it should be safe to use it.

The Whats App documentation also mention that scheme: http://www.whatsapp.com/faq/en/android/28000012

I'm using this on a production site now and will update here, if I get any user complaints.

Edit (Nov 14): No user complaints after a couple of weeks.

Aadil Keshwani
  • 1,385
  • 1
  • 18
  • 29
JonasB
  • 458
  • 3
  • 9
7

In general it makes sense only to display the Whatsapp Link on iOS or Android Devices only, using java script:

   if (navigator.userAgent.match(/iPhone|Android/i)) {
      document.write('<a href="whatsapp://send?text=See..">Share on WhatApp</a>');
   }
Weidenrinde
  • 2,152
  • 1
  • 20
  • 21
  • What did not work? The link was displayed on a non-mobile device? On the mobile device the link did not work? – Weidenrinde Mar 29 '18 at 14:50
  • The WhatsApp application opens. But neither a text nor a message displayed. Tested on several OS's and devices. I e-mailed the developers. They officially do not support this behavior "Unfortunately, that is not supported at the moment. We are always working to improve our app and will take your suggestion into consideration." (ticket #172349248330585) I have tested ~40 other services, only WhatsApp and Viber do not support their own documentation. – HoldOffHunger Mar 29 '18 at 15:08
5

Switch the whatsapp share links according to the platform whether desktop or mobile.

This works with or without providing the phone number in the link.

For Mobile

   vm.LinkTextToShare = 'https://api.whatsapp.com/send?text=' + encodeURIComponent(window.location.href) ;

   window.open(vm.LinkTextToShare,"_blank");

For Desktop

   vm.LinkTextToShare = 'https://web.whatsapp.com/send?l=en&text=' + encodeURIComponent(window.location.href) ;

   window.open(vm.LinkTextToShare,"_blank");
Sitaram
  • 428
  • 9
  • 12
  • Note for people using the OpenGraph protocol for image sharing (og:image): the desktop solution does not include the image, just the link. If you wish to include the image in the sharing, you must always use the mobile version: `https://api.whatsapp.com/send?text=` – Marcio Duarte Aug 21 '20 at 16:51
5

This code worked for me.

After clicking on the link, it will ask you to choose the contact to share a message.

<a href="https://api.whatsapp.com/send?text=enter message here">Click here to share on Whatsapp</a>

You can add target="_blank" attribute to open it in a new window or tab.

I don't think the phone number is needed when someone wants to share a particular message or article.

Rachit Mangi
  • 119
  • 2
  • 4
2

use it like "whatsapp://send?text=" + encodeURIComponent(your text goes here), it will definitely work.

2

This is correct if you want to open whatsapp in browser:

<a href=`https://web.whatsapp.com/send?text=${yout URL or TEXT}` ><Whatsapp</a>
Omid Moghadas
  • 341
  • 3
  • 8
1

Use: https://wa.me/1XXXXXXXXXX

Don't use: https://wa.me/+001-(XXX)XXXXXXX

The pre-filled message will automatically appear in the text field of a chat. Use https://wa.me/whatsappphonenumber?text=urlencodedtext where whatsappphonenumber is a full phone number in international format and urlencodedtext is the URL-encoded pre-filled message.

Example: https://wa.me/1XXXXXXXXXX?text=I'm%20interested%20in%20your%20car%20for%20sale

To create a link with just a pre-filled message, use https://wa.me/?text=urlencodedtext

Example: https://wa.me/?text=I'm%20inquiring%20about%20the%20apartment%20listing`

After clicking on the link, you’ll be shown a list of contacts you can send your message to.

WeDevelop
  • 79
  • 2
  • 13
  • Note for people using the OpenGraph protocol for image sharing (og:image): this solution does not include the image, just the link. If you wish to include the image in the sharing, you must use `https://api.whatsapp.com/` in the link. – Marcio Duarte Aug 21 '20 at 16:49
0

Try to make it this way:

<a href="https://wa.me/(phone)?text=(text URL encoded)">Link</a>

Even you can send messages without enter the phone number in the link:

<a href="https://wa.me/?text=Hello%20world!">Say hello</a>

After clicking on the link, you will be shown a list of contacts you can send your message to.

More info in https://faq.whatsapp.com/en/general/26000030.

Good luck!

Gustavo Cantero
  • 440
  • 6
  • 9