在HTML页面发送短信功能。先判断一下手机是安卓还是苹果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>html页面调用手机短信功能,判断安卓、苹果、微信</title>
<style>
#btn{
width:50%;
height:40px;
border-radius: 10px;
background:linear-gradient(to right,rgb(204, 125, 125) 0%,rgb(118, 202, 241) 100%);
margin:0 auto;
text-align:center;
line-height:40px;
}
</style>
</head>
<body>
<div id='btn'>点击发送短信</div>
<div id='sms' style='display:none'></div>
<script>
//假设给10086发送TDCX
document.getElementById('btn').οnclick=function(){
var sms=document.getElementById('sms');
var u=window.navigator.userAgent;
console.log(u);
if(u.indexOf("iPhone")>-1){
console.log('是苹果手机哦');
sms.innerHTML= " <a id='aa' href='sms:10086?body=TDCX'></a>"
//如果使用的uc浏览器就按安卓的写法
if(u.indexOf('UCBrowser')>-1){
sms.innerHTML= " <a id='aa' href='sms:10086&body=TDCX'></a>"
}
}else if(u.indexOf("Android")>-1 || u.indexOf("Linux")){
console.log('是安卓的手机哦');
sms.innerHTML= " <a id='aa' href='sms:10086&body=TDCX'></a>"
}else if(u.indexOf("Window Phone")){
console.log('是window phone,手机有点老')
}else if(u.toLowerCase.indexOf("micromessenger")>-1){
console.log('你也微信页面中打开了');
}
document.getElementById('aa').click()
}
//判断设备和浏览器
var sUserAgent = window.navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
// window.location.href = "WapUI/Main.html";
console.log('进入wap')
}
else {
// window.location.href = "WebUI/Main.html";
console.log('进入web')
}
//判断ie版本
- var IeMsg="请使用ie8或ie9浏览器";
- var flag = true;
- if(navigator.userAgent.indexOf("MSIE")>0)
- {
- if(navigator.userAgent.indexOf("MSIE 6.0")>0)
- {
- flag = false;
- }
- if(navigator.userAgent.indexOf("MSIE 7.0")>0)
- {
- flag = false;
- }
- if(navigator.userAgent.indexOf("MSIE 8.0")>0)
- {
- // alert("ie8");
- }
- if(navigator.userAgent.indexOf("MSIE 9.0")>0)
- {
- //alert("ie9");
- }
- }else
- {
- flag = false;
- }
- if(!flag){
- document.getElementById("IEUse").innerHTML=IeMsg;
- }
</script>
</body>
</html>