一、需求分析
有时间开发我们加入流量主广告,或者小程序一些功能需要只能手机端访问才生效,就需要用到判断用户是手机端打开还是电脑端打开,这就需要用到getSystemInfo获取设备信息
二、需求解决
wx.getSystemInfo({
success: function (res) {
let system = {win: false,mac: false,x11: false}
let pf = res.platform
let isPhone = true
system.win = pf.indexOf("win") == 0 || pf.indexOf("Win") == 0
system.mac = pf.indexOf("mac") == 0 || pf.indexOf("Mac") == 0
system.x11 = (pf == "X11") || (pf.indexOf("Linux") == 0) || (pf.indexOf("linux") == 0)
if (system.win || system.mac || system.x11) {
isPhone = false
}
if(isPhone==false){
wx.showModal({
title: '提示',
content: '请用手机点击获取!',
showCancel:false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
});
return false;
}else{
wx.showModal({
title: '提示',
content: '手机端端',
showCancel:false,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
});
}
}
})如果isPhone为true,则为手机端,为false为PC端。
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)