This article shares the code for calling APP using JS as follows
/* 500ms内,本机有应用程序能解析对应的协议并打开程序,调用该应用; 如果本机没有应用程序能解析该协议或者500ms内没有打开这个程序, 则执行setTimeout里面的function,跳转到下载页面。 iosAppId: appId iphoneSchema: IOS App 协议 iosAppDownloadUrl: IOS App 下载地址 https://itunes.apple.com/cn/app/id@appId@ androidSchema: Androind App 协议 androidAppDownloadUrl: Androind App 下载地址 */function opendApp(iosAppId, iphoneSchema, iosAppDownloadUrl, androidSchema, androidAppDownloadUrl){ if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //IPhone var loadDateTime = new Date(); window.setTimeout(function() { var timeOutDateTime = new Date(); if (timeOutDateTime - loadDateTime < 5000) { window.location = iosAppDownloadUrl.replace("@appId@", iosAppId);//IOS App 下载地址 } else { window.close(); } },25); window.location = iphoneSchema; //IOS App 协议 }else if (navigator.userAgent.match(/android/i)) {//Androind try { window.location = androidSchema; //Androind App 协议 setTimeout(function(){ window.location = androidAppDownloadUrl;; //Androind App 下载地址 },500); } catch(e) {} } }
The above is the detailed content of Call APP code using JS. For more information, please follow other related articles on the PHP Chinese website!