我开发了一个网站,主要用在手机上。 我想让用户直接从网页分享信息到WhatsApp。
使用UserAgent检测,我可以区分Android和iOS。 我发现,为了在iOS中实现上述功能,我可以使用URL:
href="whatsapp://send?text=http://www.example.com"
我仍然在寻找当操作系统是Android时使用的解决方案(因为上面的不工作)。 我猜这在某种程度上与在Android中使用“意图”有关,但我不知道如何将其作为href的参数。
我开发了一个网站,主要用在手机上。 我想让用户直接从网页分享信息到WhatsApp。
使用UserAgent检测,我可以区分Android和iOS。 我发现,为了在iOS中实现上述功能,我可以使用URL:
href="whatsapp://send?text=http://www.example.com"
我仍然在寻找当操作系统是Android时使用的解决方案(因为上面的不工作)。 我猜这在某种程度上与在Android中使用“意图”有关,但我不知道如何将其作为href的参数。
当前回答
就像“whatsapp://send?”text=" + encodeURIComponent(你的文本在这里),它肯定会工作。
其他回答
上面的答案有点过时了。虽然这些方法工作,但通过使用下面的方法,您可以将任何文本共享到一个预定义的数字。下面的方法适用于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>');
}
就像“whatsapp://send?”text=" + encodeURIComponent(你的文本在这里),它肯定会工作。
根据桌面或移动平台切换whatsapp分享链接。
在链接中提供电话号码或不提供电话号码都可以。
为移动
vm.LinkTextToShare = 'https://api.whatsapp.com/send?text=' + encodeURIComponent(window.location.href) ;
window.open(vm.LinkTextToShare,"_blank");
对于桌面
vm.LinkTextToShare = 'https://web.whatsapp.com/send?l=en&text=' + encodeURIComponent(window.location.href) ;
window.open(vm.LinkTextToShare,"_blank");
如果你想在浏览器中打开whatsapp,这是正确的:
<a href=`https://web.whatsapp.com/send?text=${yout URL or TEXT}` ><Whatsapp</a>