1.开发环境 vue+vant
2.电脑系统 windows10专业版
3.在h5端开发的过程中,我们经常需要点击一个按钮来判断用户使用安装了app(首先判断是安卓还是苹果,然后判断是否安装了app,如果没有安装则跳转到下载页面,如果安装了则打开)。
4.废话不多说,直接上代码:
Open APP
5.在methods中添加如下代码:
openapp() {
var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isAndroid) {
// alert("我是安卓");
this.android();
}
if (isIOS) {
// alert("我是苹果");
}
},
android() {
var _clickTime = new Date().getTime();
window.location.href = 'zhihu://'; /***打开app的协议,有安卓同事提供***/
//启动间隔20ms运行的定时器,并检测累计消耗时间是否超过3000ms