从网页打开 Whatsapp 应用程序的这两种格式之间的区别
Difference between these two formats to open the Whatsapp app from a webpage
我找到了两种从网页打开 Whatsapp 应用程序的方法,
<a href="whatsapp://send?text=Hello&phone=+1123456789">whatsapp</a>
和
<a href="https://api.whatsapp.com/send?phone=+1123456789&text=Hello">whatsapp</a>
我知道第一个只适用于 phone 但除此之外两者之间有什么区别?
在我的试验中,我发现 api 方法在某些移动浏览器中并不总是正常工作。在某些情况下,它没有检测到已安装的应用程序,而是将我带到 Appstore 以安装该应用程序。
第一种方法是否适用于所有平台和浏览器?
使用 JavaScript 检测平台(桌面或移动)然后加载适当的 link 格式是否安全?
第一种方法通常需要浏览器/OS了解如何处理whatsapp://
协议。这通常需要事先进行一些设置(例如 registering a protocol in Chrome, or a deep link schema in Android),浏览器/OS 会将请求传递给任何可以处理它的应用程序/程序。
第二种方法不需要任何设置,直接将请求传递给 WhatsApp 的 API。这不太可能完全失败,但正如您所见,当应用程序声称它应该处理对域的所有请求时,可能会在移动设备上出现问题。
您最好关注 WhatsApp's documentation,并使用他们的 wa.me
域来获得通用 link:
Universal links can also include 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 urlencodedtext
is the URL-encoded pre-filled message.
Example: https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
这将为您处理所有的复杂问题。例如,在 Android 上 URL 打开 WhatsApp 应用程序,在 Windows 上通用 link 重定向到 api.whatsapp.com
URL,并且 Chrome 询问我是否要使用我安装的 WhatsApp 程序:
我找到了两种从网页打开 Whatsapp 应用程序的方法,
<a href="whatsapp://send?text=Hello&phone=+1123456789">whatsapp</a>
和
<a href="https://api.whatsapp.com/send?phone=+1123456789&text=Hello">whatsapp</a>
我知道第一个只适用于 phone 但除此之外两者之间有什么区别?
在我的试验中,我发现 api 方法在某些移动浏览器中并不总是正常工作。在某些情况下,它没有检测到已安装的应用程序,而是将我带到 Appstore 以安装该应用程序。
第一种方法是否适用于所有平台和浏览器?
使用 JavaScript 检测平台(桌面或移动)然后加载适当的 link 格式是否安全?
第一种方法通常需要浏览器/OS了解如何处理whatsapp://
协议。这通常需要事先进行一些设置(例如 registering a protocol in Chrome, or a deep link schema in Android),浏览器/OS 会将请求传递给任何可以处理它的应用程序/程序。
第二种方法不需要任何设置,直接将请求传递给 WhatsApp 的 API。这不太可能完全失败,但正如您所见,当应用程序声称它应该处理对域的所有请求时,可能会在移动设备上出现问题。
您最好关注 WhatsApp's documentation,并使用他们的 wa.me
域来获得通用 link:
Universal links can also include a pre-filled message that will automatically appear in the text field of a chat. Use
https://wa.me/whatsappphonenumber/?text=urlencodedtext
wherewhatsappphonenumber
is a full phone number in international format andurlencodedtext
is the URL-encoded pre-filled message.Example:
https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
这将为您处理所有的复杂问题。例如,在 Android 上 URL 打开 WhatsApp 应用程序,在 Windows 上通用 link 重定向到 api.whatsapp.com
URL,并且 Chrome 询问我是否要使用我安装的 WhatsApp 程序: