Some time ago, Xiaoying companies need to achieve: the user to open a micro letter in html5, by clicking the download button, the phone will jump to Android Download in the Android html5, the IOS will jump to IOS download, then jump to the other another specified address.
1. If the user is to open the html5 browser, click the Download button will jump to the appropriate version of the app Download.
2. If the user opens the html5 micro letter, the first prompt the user to open the browser html5, html5 and then open it in your browser, then click on the download button to jump to the corresponding version of the app Download.
Specific method:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>安装</title> </head> <body> <div class="view-container"> <div class="etc-handle"> <a href="javascript:void(0)" onclick="downApp()">点击安装</a> </div> </div> <script type="text/javascript"> (function(){ window.alert = function(name){ var iframe = document.createElement("IFRAME"); iframe.style.display= "none" ; iframe.setAttribute ( "the src", 'Data: text / Plain' ); document.documentElement.appendChild (iframes); window.frames [ 0 ] .window.alert (name); iframe.parentNode.removeChild (iframes); } }) (); var browser = { versions: function () { var U = the navigator.userAgent, App = of navigator.appVersion; return { // mobile terminal browser version information trident: u.indexOf ( ' Trident ')> -1, // IEs core Presto: u.indexOf ( 'Presto')> -1, // Opera core WebKit: u.indexOf ( 'AppleWebKit')> -1, // Apple, Google kernel gecko: u.indexOf ( 'Gecko') > - && u.indexOf. 1 ( 'KHTML') == -1, // Firefox kernel mobile: !! u.match (. /AppleWebKit.*Mobile * /), // whether the mobile terminal ios: !! u.match ?. (/ \ (I [^;] +; (the U-;) the CPU the Mac the OS X-+ /), // iOS terminal android: u.indexOf ( 'Android') > -1 || u.indexOf ( 'Linux ')> -1, // Android terminal uc browser or iPhone: u.indexOf (' iPhone ') > -1,// whether or QQHD browser iPhone iPad: u.indexOf ( 'iPad') > -1,// whether the iPad webApp: u.indexOf ( 'Safari') == -1 // if the web application should not bottom head }; } (), Language: (navigator.browserLanguage || navigator.language) .toLowerCase () } function downApp () { var URLs = { 'Android': 'XXX.apk' , 'iOS': 'XXX / id1438617787' , 'OTHER': 'HTTPS: //www.baidu.com/index.php ? TN = monline_3_dg ' }; iF (browser.versions.mobile) { // determines whether the mobile device is opened. In the following code browser var UA = the navigator.userAgent.// Get the object is determined by the IF (ua.match (/ MicroMessenger / I) == "micromessenger" ) { Alert ( "top right button click, pop-up menu and then click to open in a browser, to install " ); } the else IF (browser.versions.ios) { window.location.href = urls.ios; } the else IF (browser.versions.android) { window.location.href = urls.android; } } the else { window .location.href = urls.other; } } </ Script> </ body> </ HTML>