IOS和安卓共用一個二維碼,實現掃碼跳轉連結-踩坑記_04
阿新 • • 發佈:2018-12-11
ios和安卓共用一個二維碼,實現掃碼跳轉連結
直接上程式碼了 也是參考了網上的demo,直接小修改了一下。臨時接了一個任務,直接套過來了。因為安卓微信的內建的瀏覽器和手機自帶的不一樣,在ios上面沒有問題,會直接提示跳轉到appstore。要求是實現安卓微信跳轉顯示一個頁面,提示用手機自帶的瀏覽器開啟下載,就這麼小修改了一下。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>download</title> </head> <div id="weixin-tip" style="margin: 0px; background: #0e0e0e;"></div> <body> <script> //二維碼掃碼 goDownload(); // 去下載 function goDownload() { var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // 這裡是安卓瀏覽器 if (isAndroid) { if (is_weixn()) { var weixin_tip = document.getElementById("weixin-tip"); var img = document.createElement("img"); img.src = "#"; weixin_tip.appendChild(img); } else { window.location.href = '#'; } }; // 這裡是iOS瀏覽器 if (isIOS) { window.location.href = '#'; // 跳AppStore下載地址 } } // 微信掃碼判斷 function is_weixn() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } }; </script> </body>