277

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.

2
  • 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 4, 2019 at 19:29
  • 1
    Which contact will receive this message?
    – Codebeat
    Jul 24, 2019 at 1:51

16 Answers 16

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.

12
  • 1
    indeed it seems that the original URL in my question also works now for Android.
    – Yochai
    Oct 11, 2014 at 22:15
  • Whoever upvoted @MosheL's undoubtedly insightful comment must have intimate knowledge of what exactly his "item" is. Jul 11, 2015 at 4:26
  • 10
    @Manuel what is data-action="share/whatsapp/share" for? Jul 28, 2015 at 7:43
  • 4
    The Data should be in url encoded form.otherwise it will send blank message in whatsapp iphone. Nov 20, 2015 at 10:21
  • 1
    Some API changes can be found in recent document - faq.whatsapp.com/en/general/26000030/?category=5245251 Jun 21, 2018 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

6
  • 2
    I tested this in all devices. All it does is open the whatsapp application. Nothing happens afteward. Tested multiple devices (iOS, Android, Windows). Mar 27, 2018 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 4, 2018 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: github.com/bradvin/social-share-urls/blob/master/README.md Apr 4, 2018 at 12:30
  • Works on WhatsApp Desktop under Mojave
    – Alchem
    Feb 26, 2019 at 8: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. Jul 16, 2019 at 0:57
48

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. :-)

7
  • 3
    For encode your content to share use encodeURIComponent()
    – nikoskip
    Nov 26, 2014 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, 2014 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, 2014 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, 2015 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, 2017 at 9:48
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>
6
  • 3
    So it's also possible without a phone number. This doc can be found here: faq.whatsapp.com/en/general/26000030 Oct 22, 2018 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 Jul 16, 2019 at 0: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 Aug 13, 2019 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. Aug 21, 2019 at 15:21
  • Ok, did you try my 2nd option ? fairly I didn't try on mobile brower, I will try tomorrow Aug 21, 2019 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

7
  • Using whatsapp://send?text= does work for me, with or without URL encode. Only tested it on iOS
    – Snowball
    Jun 14, 2018 at 8: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. Jun 18, 2020 at 18:39
  • 1
    This is the best solution if you wish to include an OpenGraph image (og:image) in the sharing. Aug 21, 2020 at 16:49
  • @HoldOffHunger how can we share images with this api.whatsapp link?
    – Developer
    Nov 3, 2020 at 20:39
  • @GuarangDhorda: use the og:image tag. Nov 3, 2020 at 22:16
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

5
  • I tested this personally. It opens the application, but nothing else. Mar 28, 2018 at 13:20
  • @HoldOffHunger because you have need to use urlencode otherwise it will not work
    – Shiv Singh
    May 8, 2018 at 11:30
  • @Shiv: That was not my problem. May 8, 2018 at 14:15
  • This is working fore sure... Any way to insert line breaks (enter keys) in the message text?
    – cht
    Jun 12, 2018 at 6:18
  • @cht kinda late, but you can use %0D as line breaks
    – Elro444
    Apr 11, 2019 at 12:01
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

2
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!

2
  • 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, 2014 at 14:44
  • I was able to get in contact with the WhatsApp devs. They admitted this feature is not supported. Mar 28, 2018 at 13:13
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>');
   }
2
  • What did not work? The link was displayed on a non-mobile device? On the mobile device the link did not work? Mar 29, 2018 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. Mar 29, 2018 at 15:08
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.

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");
1
  • 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= Aug 21, 2020 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.

1
  • can this be opened in browser desktop? so forwarded to web.whatsapp page?
    – gumuruh
    May 13, 2020 at 6:09
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>
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.

1
  • 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. Aug 21, 2020 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!

2
  • whatsapp says We couldn't find the page you were looking for Jun 4, 2020 at 1:28
  • I don't understand. WhatsApp shows that error? When? Jun 4, 2020 at 16:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.