Last active
March 5, 2018 09:57
-
-
Save mirinzhang/a9aad356fc91fa9d169428bcc2b93497 to your computer and use it in GitHub Desktop.
Revisions
-
泡面君 revised this gist
Mar 5, 2018 . No changes.There are no files selected for viewing
-
泡面君 revised this gist
Mar 5, 2018 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,10 @@ function openOrDownloadApp(microLink, schemeUrl, downloadUrl) { // 收集设备信息 var deviceInfo = { userAgent: navigator.userAgent.toLowerCase(), isAndroid: !!navigator.userAgent.match(/android/ig), isIphone: !!navigator.userAgent.match(/iphone|ipod/ig), isIpad: !!navigator.userAgent.match(/ipad/ig), isWeixin: !!navigator.userAgent.match(/MicroMessenger/ig), }; // 如果是在微信中打开,则使用微下载进行打开或下载APP -
泡面君 created this gist
Mar 5, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ /** * @param microLink 应用宝微下载链接 * @param schemeUrl 需要打开的schemeUrl * @param downloadUrl App通用下载地址 */ function openOrDownloadApp(microLink, schemeUrl, downloadUrl) { // 收集设备信息 var deviceInfo = { userAgent: navigator.userAgent.toLowerCase(), isAndroid: !!navigator.userAgent.match(/android/ig), isIphone: !!navigator.userAgent.match(/iphone|ipod/ig), isIpad: !!navigator.userAgent.match(/ipad/ig), isWeixin: !!navigator.userAgent.match(/MicroMessenger/ig), }; // 如果是在微信中打开,则使用微下载进行打开或下载APP if(deviceInfo.isWeixin) { window.location.href = microLink + '&android_schema=' + window.encodeURI(schemeUrl); return; } // 非微信环境,先尝试打开App var iframe = document.createElement('iframe'); iframe.src = schemeUrl; iframe.style.display = 'none'; document.body.appendChild(iframe); // 若2秒内未打开App则说明未安装App,跳转到App下载页面 window.setTimeout(function() { document.body.removeChild(iframe); window.location.href = downloadUrl; }, 2000); }