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

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

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

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


当前回答

最新更新

现在您可以使用来自whatsapp https://wa.me/的最新API,而无需担心用户代理,API将执行用户代理处理。

在各自的whatsapp客户端(Android / iOS / Webapp)中共享带有联系人选择选项的预填充文本:

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

在各自的whatsapp客户端(Android / iOS / Webapp)中打开特定whatsapp用户的聊天对话框:

https://wa.me/whatsappphonenumber

与特定用户共享预填充文本(结合以上两个):

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

注意:whatsappphonenumber应该是国际格式的完整电话号码。在添加国际格式的电话号码时,请省略任何零、括号或破折号。

官方文件请访问https://faq.whatsapp.com/en/general/26000030

其他回答

最近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

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

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

根据新的文档,链接现在是:

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

如果不奏效,试试下面这个:

<a href="whatsapp://send?text=urlencodedtext">Share this</a>

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

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