从适用于 Android 的移动网站(而非应用程序)在 WhatsApp 上共享链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21935149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sharing link on WhatsApp from mobile website (not application) for Android
提问by Yochai
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.
我开发了一个主要用于手机的网站。
我希望允许用户直接从网页共享信息到 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:
使用 UserAgent 检测,我可以区分 Android 和 iOS。
我发现为了在 iOS 中实现上述内容,我可以使用 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.
我仍在寻找操作系统为 Android 时要使用的解决方案(因为上述方法不起作用)。
我想这与在 Android 中使用“意图”有某种关系,但我无法弄清楚如何将其作为 href 的参数。
回答by Manuel
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!
刚刚在网站上看到它,现在似乎也可以在带有最新 chrome 和 whatsapp 的最新 Android 上运行!给链接一个新的镜头!
<a href="whatsapp://send?text=The text to share!" data-action="share/whatsapp/share">Share via Whatsapp</a>
Rechecked it today (17thApril 2015):
Works for me on iOS 8 (iPhone 6, latest versions) Android 5 (Nexus 5, latest versions).
今天重新检查(2015 年 4 月17日):
适用于 iOS 8(iPhone 6,最新版本)Android 5(Nexus 5,最新版本)。
It also works on Windows Phone.
它也适用于 Windows Phone。
回答by ad08
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.
上面的答案有点过时了。虽然这些方法有效,但通过使用以下方法,您可以将任何文本共享到预定义的数字。以下方法适用于 android、WhatsApp web、IOS 等。
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)
更新--从现在开始使用(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=urlencodedtextwhere 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: //wa.me/+001-(555)1234567
要使用自动出现在聊天文本字段中的预填充消息创建您自己的链接,请使用 https://wa.me/whatsappphonenumber/?text=urlencodedtext其中 whatsappphonenumber 是国际格式和 URL 的完整电话号码-encodedtext 是 URL 编码的预填充消息。
示例:https: //wa.me/15551234567?text =I 'm%20interested%20in%20your%20car%20for%20sale
要创建仅包含预填充消息的链接,请使用 https://wa.me/?text=urlencodedtext
示例:https: //wa.me/?text =I'm%20inquiring%20about%20the%20apartment%20listing
单击链接后,您将看到一个联系人列表,您可以向其发送消息。
For more information, see https://www.whatsapp.com/faq/en/general/26000030
回答by juangalf
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.
就是这样。不需要Javascript,不需要其他任何东西。当然,您可以根据需要设置样式并包含一个漂亮的 Whatsapp 图标。
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
- 安卓 4.1.2(果冻豆)
- Chrome 移动版 37.0.2062.117。还在 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.
它也适用于 iOS。我已经使用 Safari 在 iPhone 5 上进行了快速测试,它也能正常工作。
Hope this helps someone. :-)
希望这可以帮助某人。:-)
回答by Vincent Decaux
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>
回答by Aadil Keshwani
Recently WhatsApp updated on its official websitethat we need to use this HTML tag in order to make it shareable to mobile sites:
最近 WhatsApp 在其官方网站上更新,我们需要使用此 HTML 标签才能将其共享到移动网站:
<a href="whatsapp://send?text=Hello%20World!">Hello, world!</a>
You can replace text=
to have your link or any text content
您可以替换text=
以获取链接或任何文本内容
回答by Shri
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.
现在您可以使用来自 whatsapp 的最新 APIhttps://wa.me/
而无需担心用户代理,API 将执行用户代理处理。
Share pre-filled text with contact selection option in respective whatsapp client (Android / iOS / Webapp):
在相应的whatsapp客户端(Android / iOS / Webapp)中使用联系人选择选项共享预填充文本:
https://wa.me/?text=urlencodedtext
Open Chat Dialog for a particular whatsapp user in respective whatsapp client (Android / iOS / Webapp):
在相应的 whatsapp 客户端(Android / iOS / Webapp)中为特定的 whatsapp 用户打开聊天对话框:
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.
注意:whatsappphonenumber
应为国际格式的完整电话号码。添加国际格式的电话号码时,请省略任何零、括号或破折号。
For official documentation visit https://faq.whatsapp.com/en/general/26000030
回答by Weidenrinde
In general it makes sense only to display the Whatsapp Link on iOS or Android Devices only, using java script:
一般来说,只在 iOS 或 Android 设备上显示 Whatsapp 链接才有意义,使用 java 脚本:
if (navigator.userAgent.match(/iPhone|Android/i)) {
document.write('<a href="whatsapp://send?text=See..">Share on WhatApp</a>');
}
回答by JonasB
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.
刚刚测试了whatsapp://
我的超级老方案Android 2.3.3
有Whats App 2.11.301
,就像一个魅力。好像只有Whats App
版本。既然Whats App
是强制大家更新,用起来应该是安全的。
The Whats App
documentation also mention that scheme: http://www.whatsapp.com/faq/en/android/28000012
该Whats App
文件还提到,方案: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.
编辑(11 月 14 日):几周后没有用户投诉。
回答by oliferna
I'm afraid that WhatsApp for Android does not currently support to be called from a web browser.
恐怕 WhatsApp for Android 目前不支持从网络浏览器调用。
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.
我对我当前的项目有同样的要求,由于找不到任何合适的信息,我最终下载了 APK 文件。
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.
在 Android 中,如果应用程序想要从 Web 浏览器调用,它需要定义一个类别为 android.intent.category.BROWSABLE 的 Activity。
You can find more information about this here: https://developers.google.com/chrome/mobile/docs/intents
您可以在此处找到更多相关信息: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:
如果您查看 WhatsApp AndroidManifest.xml 文件,则唯一具有 BROWSABLE 类别的 Activeiy 是这个:
<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.
我已经玩了一段时间了,我无法让它工作。我得到的最多的是从 Chrome 打开 WhatsApp 应用程序,但我想不出设置消息内容和收件人的方法。
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.
由于WhatsApp团队没有记录,我认为这仍在进行中。看起来未来 WhatsApp 也会处理短信。
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.
获取更多信息的唯一方法是联系 WhatsApp 开发团队,这是我尝试过的方法,但我仍在等待回复。
Regards!
问候!
回答by HoldOffHunger
The official docs say to use: wa.me
. Don't use wa.me
. Just try it for yourself: https://wa.me/?text=SomeTexttoShareResults for me:
官方文档说使用:wa.me
. 不要使用wa.me
. 自己试试吧:https: //wa.me/?text=SomeTexttoShare 我的结果:
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.
我们找不到您要找的页面
看起来您正在寻找一个不存在的页面。或者我们可能刚刚删除的页面。无论哪种方式,请返回或确保检查网址、拼写并重试。
If you want to share, you must absolutely use one of the two following URL formats:
如果要共享,则必须绝对使用以下两种 URL 格式之一:
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#telegramme
如果您有兴趣观看跟踪这些 URL 的项目,请查看我们!:https: //github.com/bradvin/social-share-urls#telegramme