我创建了一个简单的表单,其中包含提交按钮、文本和电话条目。当我按下发送按钮时,whatsapp web 将打开,当我从手机输入时,whatsapp.com 将打开。 我正在尝试用我写的文字打开 Whatsapp 的移动应用程序
let number = mobileNumber.replace(/[^\d]/g, "");
let url = `whatsapp://send?phone=${number}&text=${encodeURIComponent(message)}`;
chatGPT 已经告诉我
https://wa.me/15551234567
这会起作用
let number = mobileNumber.replace(/[^\d]/g, "");
let url = `whatsapp://send?phone=${number}&text=${encodeURIComponent(message)}`;
WhatsApp 应该打开 - 根据 https://faq.whatsapp.com/425247423114725/ 的文档 - 使用他们的
https://wa.me/<number>?text=<text>
URL。
提到的数字15551234567来自那些特定的文档,只是一个例子。
那么,尝试一下吧
let number = mobileNumber.replace(/[^\d]/g, "");
let url = `https://wa.me/${number}?text=${encodeURIComponent(message)}`;
<html>
<body>
<a href="" id="link">
click to send WA message
</a>
<p><code></code></p>
<script>
const mobileNumber = "+1-555-123456";
const message = "Hello to WhatsApp!";
let number = mobileNumber.replace(/[^\d]/g, "");
let url = `https://wa.me/${number}?text=${encodeURIComponent(message)}`;
document.querySelector("#link").setAttribute("href", url);
document.querySelector("code").innerText = url;
</script>
</body>
</html>