我开发了一个网站,主要用在手机上。 我想让用户直接从网页分享信息到WhatsApp。

使用UserAgent检测,我可以区分Android和iOS。 我发现,为了在iOS中实现上述功能,我可以使用URL:

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

我仍然在寻找当操作系统是Android时使用的解决方案(因为上面的不工作)。 我猜这在某种程度上与在Android中使用“意图”有关,但我不知道如何将其作为href的参数。


当前回答

使用:https://wa.me/1XXXXXXXXXX 不要使用:https://wa.me/+001-(XXX)XXXXXXX

预先填写的消息将自动出现在聊天的文本框中。使用https://wa.me/whatsappphonenumber?text=urlencodedtext,其中whatsappphonenumber是国际格式的完整电话号码,urlencodedtext是url编码的预填充消息。

例子: https://wa.me/1XXXXXXXXXX?text=I是% 20感兴趣% 20 % 20你% 20辆车% 20 % 20出售

要创建只包含预填充消息的链接,请使用https://wa.me/?text=urlencodedtext

例子: https://wa.me/?text=I是% 20的% 20约% 20 % 20公寓% 20清单”

点击链接后,你会看到一个联系人列表,你可以将消息发送给这些联系人。

其他回答

一般来说,只在iOS或Android设备上使用java脚本显示Whatsapp Link是有意义的:

   if (navigator.userAgent.match(/iPhone|Android/i)) {
      document.write('<a href="whatsapp://send?text=See..">Share on WhatApp</a>');
   }

最近WhatsApp在官网上更新了我们需要使用的内容 这个HTML标签,以使其可共享到移动网站:

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

您可以替换text=来拥有您的链接或任何文本内容

上面的答案有点过时了。虽然这些方法工作,但通过使用下面的方法,您可以将任何文本共享到一个预定义的数字。下面的方法适用于android, WhatsApp web, IOS等。

你只需要使用下面的格式:

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

更新—从现在开始使用(2018年11月)

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

欲了解更多信息,请参见https://www.whatsapp.com/faq/en/general/26000030

如果你想在浏览器中打开whatsapp,这是正确的:

<a href=`https://web.whatsapp.com/send?text=${yout URL or TEXT}` ><Whatsapp</a>

就像“whatsapp://send?”text=" + encodeURIComponent(你的文本在这里),它肯定会工作。