Html 移动网站“WhatsApp”按钮可向特定号码发送消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29218378/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:42:54  来源:igfitidea点击:

Mobile website "WhatsApp" button to send message to a specific number

htmlmobile-websitewhatsapp

提问by Lyric Roy

A mobile website can be customized to allow users to share a pre-filled message in WhatsApp to a manually chosen contact. As given hereit is done using Custom URL Scheme. An example:

可以自定义移动网站,以允许用户将 WhatsApp 中预先填写的消息分享给手动选择的联系人。正如这里给出的它是使用自定义 URL 方案完成的。一个例子:

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

To call a particular number we use:

要拨打特定号码,我们使用:

<a href="tel:0123456789">Call</a>

Similarly, can we send a WhatsApp message to a specific number (or at least open the chat) without user choosing the phone number manually rather it will be one of the predefined parameters/attribute values?

同样,我们是否可以将 WhatsApp 消息发送到特定号码(或至少打开聊天),而无需用户手动选择电话号码,而是将其作为预定义的参数/属性值之一?

回答by ad08

Format to send a WhatsApp message to a specific number (updated Nov 2018)

将 WhatsApp 消息发送到特定号码的格式(2018 年 11 月更新)

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

where

在哪里

whatsappphonenumberis a full phone number in international format

urlencodedtextis the URL-encoded pre-filled message.

whatsappphonenumber是国际格式的完整电话号码

urlencodedtext是 URL 编码的预填充消息。



Example:

例子:

  1. Create a link with a pre-filled message that will automatically appear in the text field of a chat, to be sent to a specific number

    Send I am interested in your car for saleto +001-(555)1234567

    https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20car%20for%20sale

    Note :

    Use: https://wa.me/15551234567

    Don't use: https://wa.me/+001-(555)1234567

  2. Create a link with just a pre-filled message that will automatically appear in the text field of a chat, number will be chosen by the user

    Send I am enquiring about the apartment listing

    https://wa.me/?text=I%20am%20enquiring%20about%20the%20apartment%20listing

    After clicking on the link, user will be shown a list of contacts they can send the pre-filled message to.

  1. 创建一个带有预填充消息的链接,该消息将自动出现在聊天的文本字段中,发送到特定号码

    发送我感兴趣的汽车销售+ 001-(555)1234567

    https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20car%20for%20sale

    笔记 :

    使用:https: //wa.me/15551234567

    不要使用:https: //wa.me/+001-(555)1234567

  2. 创建一个仅包含预填充消息的链接,该消息将自动出现在聊天的文本字段中,用户将选择数字

    发送我正在查询公寓列表

    https://wa.me/?text=I%20am%20enquiring%20about%20the%20apartment%20listing

    单击链接后,用户将看到他们可以向其发送预填充消息的联系人列表。

For more information, see https://www.whatsapp.com/faq/en/general/26000030

有关更多信息,请参阅https://www.whatsapp.com/faq/en/general/26000030

--

——

P.S : Older format (before updation) for reference

PS:旧格式(更新前)供参考

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

回答by Oscar Caicedo

On android, you can try

在安卓上,你可以试试

href="intent://send/[countrycode_without_plus][number]#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end

replace [countrycode_without_plus][number]with the number,

替换[countrycode_without_plus][number]为数字,

回答by Shri

WhatsApp is now providing a much simpler API https://wa.me/This isn't introducing any new features, just a simpler way to execute things. There's no need to check for user agent while implementing this API as it will also work with native apps as well as the web interface of whatsapp (web.whatsapp.com) on desktop.

WhatsApp 现在提供了一个更简单的 APIhttps://wa.me/这并没有引入任何新功能,只是一种更简单的执行方式。在实现此 API 时无需检查用户代理,因为它也适用于本机应用程序以及桌面上的 whatsapp (web.whatsapp.com) 的 Web 界面。

This can be used in multiple use cases

这可以用于多个用例

  • A Click to chatbutton : Use https://wa.me/whatsappphonenumberto open a chat dialog with the specified whatsapp user. Please note that the whatsappphonenumbershould be a valid whatsapp number in international format without leading zeros, '+', '-' and spaces. e.g. 15551234567

    <a href="https://wa.me/15551234567">Whatsapp Me</a>

  • A Share this on whatsappbutton : Use https://wa.me/?text=urlencodedtextto open a whatsapp contact selection dialog with a preset text. e.g.

    <a href="https://wa.me/?text=I%20found%20a%20great%20website.%20Check%20out%20this%20link%20https%3A%2F%2Fwww.example.com%2F">Share on WhatsApp</a>

  • A Contact mebutton with prefilled text: A combination of the above two, Might be useful if you want to get a prefilled custom message from users landing on a particular page. Use format https://wa.me/whatsappphonenumber/?text=urlencodedtext

    <a href="https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20services.%20How%20to%20get%20started%3F">I am interested</a>

  • A单击聊天按钮:https://wa.me/whatsappphonenumber用于打开与指定 whatsapp 用户的聊天对话框。请注意,该whatsappphonenumber号码应该是国际格式的有效 whatsapp 号码,没有前导零、“+”、“-”和空格。例如 15551234567

    <a href="https://wa.me/15551234567">Whatsapp Me</a>

  • A在 whatsapp按钮上分享此内容https://wa.me/?text=urlencodedtext用于打开带有预设文本的 whatsapp 联系人选择对话框。例如

    <a href="https://wa.me/?text=I%20found%20a%20great%20website.%20Check%20out%20this%20link%20https%3A%2F%2Fwww.example.com%2F">Share on WhatsApp</a>

  • 带有预填充文本的“联系我”按钮:以上两者的组合,如果您想从登陆特定页面的用户那里获得预填充的自定义消息,可能会很有用。使用格式https://wa.me/whatsappphonenumber/?text=urlencodedtext

    <a href="https://wa.me/15551234567?text=I%20am%20interested%20in%20your%20services.%20How%20to%20get%20started%3F">I am interested</a>

For official documentation visit https://faq.whatsapp.com/en/general/26000030

有关官方文档,请访问https://faq.whatsapp.com/en/general/26000030

回答by Umair Mehmood

i used this code and it works fine for me, just change +92xxxxxxxxxxto your valid whatsapp number, with country code

我使用了这个代码,它对我来说很好用,只需将+92xxxxxxxxxx更改为您的有效 whatsapp 号码,并带有国家/地区代码

<script type="text/javascript">
        (function () {
            var options = {
                whatsapp: "+92xxxxxxxxxx", // WhatsApp number
                call_to_action: "Message us", // Call to action
                position: "right", // Position may be 'right' or 'left'

            };
            var proto = document.location.protocol, host = "whatshelp.io", url = proto + "//static." + host;
            var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/widget-send-button/js/init.js';
            s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
            var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
        })();
    </script> 

回答by Santiago Bernal

unfortunately, there is not option to put number in whatsapp protocol. only is possible with parameter ABID (address Book ID), but you must have this contact with specific name to do this. check WhatsApp Documentation

不幸的是,没有选项可以在 whatsapp 协议中输入号码。仅可使用参数 ABID(地址簿 ID),但您必须让此联系人具有特定名称才能执行此操作。检查WhatsApp 文档

回答by imtaher

This answer is useful to them who want click to chat whatsapp in website to redirect web.whatsapp.com with default content or message and in mobile device to open in whatsapp in mobile app with default content to text bar in app.

这个答案对于想要点击网站中的 whatsapp 聊天以使用默认内容或消息重定向 web.whatsapp.com 以及在移动设备中以在移动应用程序中的 whatsapp 中打开并使用默认内容到应用程序中的文本栏的人很有用。

also add jquery link.

还添加 jquery 链接。

<a  target="_blank" title="Contact Us On WhatsApp" href="https://web.whatsapp.com/send?phone=+91xxxxxxxxx&amp;text=Hi, I would like to get more information.." class="whatsapplink hidemobile" style="background-color:#2DC100">
<i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
<span style="color:#fff">
    Contact Us On WhatsApp        </span>
</a>
<a  target="_blank" title="Contact Us On WhatsApp" href="https://api.whatsapp.com/send?phone=+91xxxxxxxxx&text=Hi,%20I%20would%20like%20to%20get%20more%20information.." class="whatsapplink hideweb" style="background-color:#2DC100">
<i class="fa fa-fw fa-whatsapp" style="color:#fff"></i>
<span style="color:#fff">
    Contact Us On WhatsApp        </span>
</a>

<script type="text/javascript"> 
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
if (mobile) { 

$('.hidemobile').css('display', 'none'); // OR you can use $('.hidemobile').hide();
} 
else 
{ 
$('.hideweb').css('display', 'none'); // OR you can use $('.hideweb').hide();
}
</script>

回答by HoldOffHunger

As noted by others, the official documentation is available here: WhatsApp.com FAQ: Android -> Chats -> How to use click to chat. The documentation states:

正如其他人所指出的,官方文档可在此处获得:WhatsApp.com 常见问题解答:Android -> Chats -> How to use click to chat。该文件指出:

Example: https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale

示例:https: //wa.me/15551234567?text =I 'm%20interested%20in%20your%20car%20for%20sale

BUT!Why don't we try copying that into a new tab in your browser and going there right now?

但!我们为什么不尝试将其复制到浏览器中的新选项卡中,然后立即前往那里?

https://wa.me/text=testtesttesttest

https://wa.me/text=testtesttesttest

Results: ERROR PAGE NOT FOUND.

结果:找不到错误页面。

What gives???

是什么赋予了???

Fix it easily by using one of THESEformat:

通过使用一个容易解决它THESE格式:

https://api.whatsapp.com/send?text=YourShareTextHere
https://api.whatsapp.com/send?text=YourShareTextHere&phone=123

No wa.me domain in this URL!

此 URL 中没有 wa.me 域!

WhatsApp send text page.

WhatsApp 发送文本页面。