当前位置: 首页 > news >正文

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

移动端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>
http://www.lryc.cn/news/190723.html

相关文章:

  • spring boot RabbitMq基础教程
  • springboot vue 部署至Rocky(Centos)并自启,本文部署是若依应用
  • Mysql之增删改查
  • 【考研数学】矩阵三大关系的梳理和讨论 | 等价、相似、合同
  • 在 Amazon SageMaker 上使用 ESMFold 语言模型加速蛋白质结构预测
  • node.js知识系列(4)-每天了解一点
  • can not remove .unionfs
  • 微服务 BFF 架构设计
  • 零基础学python之元组
  • 11. SpringBoot项目中参数获取与响应
  • 4+1视图与UML
  • 没用的知识增加了,尝试用文心实现褒义词贬义词快速分类
  • AWS SAP-C02教程3--网络资源
  • 【TensorFlow2 之012】TF2.0 中的 TF 迁移学习
  • mysql面试题46:MySQL中datetime和timestamp的区别
  • 【Spring Boot】RabbitMQ消息队列 — RabbitMQ入门
  • Navicat定时任务
  • 小白必备:简单几步, 使用Cpolar+Emlog在Ubuntu上搭建个人博客网站
  • 封装 Token
  • CloudCompare 二次开发(17)——点云添加均匀分布的随机噪声
  • 研发必会-异步编程利器之CompletableFuture(含源码 中)
  • 上海亚商投顾:沪指高开高走 锂电等新能源赛道大反攻
  • 力扣第235题 二又搜索树的最近公共祖先 c++
  • 时代风口中的Web3.0基建平台,重新定义Web3.0!
  • React学习笔记 001
  • 2023 | github无法访问或速度慢的问题解决方案
  • unity各种插件集合(自用)
  • 内网收集哈希传递
  • 前端目录笔记
  • Sui主网升级至V1.11.2版本