版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
最近在做一个这样的功能,前端网页点击按钮时,如果用户手机有安装该app,则直接打开app;否则就跳到应用市场下载。代码如下:

打开客户端	document.getElementById('openApp').onclick = function(e) {	//ios	if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {	var browser = navigator.userAgent.toLowerCase();	if(browser.match(/micromessenger/i)) {	//微信内置浏览器	window.location.href ="hengtaixin://";	window.setTimeout(function() {	window.location.href = "https://itunes.apple.com/us/app/cheng-shi-gao-er-fu/id1008696844?mt=8&uo=4";	}, 1000)	return	} else {	window.location.href ="hengtaixin://"; //ios app协议,由ios同事提供	window.setTimeout(function() {	window.location.href = "https://itunes.apple.com/us/app/cheng-shi-gao-er-fu/id1008696844?mt=8&uo=4";	&#