web唤起whatsapp客户端通过号码联系
如果安装了whatsapp客户端,只需跳转
window.location.href = "https://wa.me/号码";
如果有区号则只需在前面直接加区号,例如加香港区号:
https://wa.me/852XXXXXXXX
if (window.navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { window.location.href = "https://wa.me/号码"; setTimeout(function () { window.location.href = "https://itunes.apple.com/us/app/whatsapp-messenger/id310633997?mt=8"; window.location.href = "https://itunes.apple.com/us/app/whatsapp-messenger/id310633997?mt=8"; }, 2000); } else if (window.navigator.userAgent.match(/android/i)) { window.location.href = "https://wa.me/号码";; setTimeout(function () { window.location.href = "https://play.google.com/store/apps/details?id=com.whatsapp"; }, 2000) }
或者可以到 http://www.conversabit.com/wasap.js/ 提供的小插件自动适配
html:
<span data-whatsapp="5215585420898">This will be clickable on mobile</span>
javascript:
wasap.init()
插件还能配合vue应用,具体查看官网