在我的网站中,我有一个 Whatsapp 共享按钮,因此我想发送带有参数的网站链接,
例如
abcd.com/?name=userinput
这是whatsapp分享按钮的代码。
<script type="text/javascript">
var userinput=prompt("Please Enter Your Name");
</script>
<script><a href="whatsapp://send?text= Link abcd.html?name="><b>share on whatsapp</b></script>
最佳答案
你可以这样做:
JS:
<script>
//Ask the user for name and store it on name variable
var name = prompt("Please Enter Your Name");
//This will be called when the link is clicked
function sendWhatsapp(){
var url = "www.abcd.com/?name=" + name;
var sMsg = encodeURIComponent( "hi this is " + name + " and my link is " + url );
var whatsapp_url = "whatsapp://send?text=" + sMsg;
window.location.href = whatsapp_url;
}
</script>
HTML:
<a onclick="sendWhatsapp()">share on whatsapp</a>
<小时/>
完整 HTML 代码:
<html>
<head>
<script>
//Ask the user for name and store it on name variable
var name = prompt("Please Enter Your Name");
//This will be called when the link is clicked
function sendWhatsapp(){
var url = "www.abcd.com/?name=" + name;
var sMsg = encodeURIComponent( "hi this is " + name + " and my link is " + url );
var whatsapp_url = "whatsapp://send?text=" + sMsg;
window.location.href = whatsapp_url;
}
</script>
</head>
<body>
<a onclick="sendWhatsapp()">share on whatsapp</a>
</body>
</html>
关于javascript - 如何在whatsapp共享消息中写入用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47729544/