当前位置:首页 > 编程笔记 > 正文
已解决

vue移动端H5调起手机发送短信(兼容ios和android)

来自网友在路上 177877提问 提问时间:2023-10-14 15:56:12阅读次数: 77

最佳答案 问答题库778位专家为你答疑解惑

移动端h6页面调起手机发送短信功能,ios和android的兼容写法不一样。

android

window.location.href = `sms:10086?body=${encodeURIComponent('Hello, 测试短信发送')}`

 ios

window.location.href = `sms:10086&body=${encodeURIComponent('Hello, 测试短信发送')}`//或者window.location.href =`sms:/open?addresses=10086&body=${encodeURIComponent('Hello, 测试短信发送')}`;
<template><view @click="openNewSmsPage"></view>
</template>
<script lang="ts" setup>
//点击唤起短信发送
const openNewSmsPage = () => {const phoneNumber = '10086' // 目标手机号码const message = 'Hello, 测试短信发送' // 短信内容let smsLink = ''const u = navigator.userAgent,isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1,isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);if (isIOS) {// window.location.href = 'sms:10086&body=' + msgsmsLink = `sms:${phoneNumber}&body=${encodeURIComponent(message)}`//或者smsLink = `sms:/open?addresses=${phoneNumber}&body=${encodeURIComponent(message)}`;} else {// sms:后面跟收件人的手机号,body后接短信内容smsLink = `sms:${phoneNumber}?body=${encodeURIComponent(message)}`}window.location.href = smsLink
}
</script>
查看全文

99%的人还看了

相似问题

猜你感兴趣

版权申明

本文"vue移动端H5调起手机发送短信(兼容ios和android)":http://eshow365.cn/6-19440-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!