;(function(win){ win.onload = function(){ var DownloadApp = function(){ //判断设备及浏览器 function isDevice(device){ var userAgent = window.navigator.userAgent; var dev = device || 'no device'; // var devReg = /+device+/gi; if(eval('/'+device+'/gi').test(userAgent)){ return true; } return false; }; var Download = function(dom,iphoneUrl,androidUrl,layerUrl){ this.ele = dom || window; this.iphoneUrl = iphoneUrl || ''; this.androidUrl = androidUrl || ''; this.layerUrl = layerUrl || ''; } Download.prototype = { init: function(option){ var _that = this; var ifrSrc = null; if(isDevice('iphone')){ ifrSrc = 'rice://'; document.querySelector('#startApp').click(); // 获取APP版本号 }else if(isDevice('android')){ ifrSrc = 'app://rice'; // 获取APP版本号 } var ifr = document.createElement('iframe'); ifr.src = ifrSrc; ifr.style.display = 'none'; ifr.onload = function() { // alert('loaded') }; ifr.onerror = function() {}; document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); },1000); this.ele.onclick=function(e){ if(isDevice('micromessenger') || isDevice('alipayclient')){ _that.createGuideLayer(); }else{ if(isDevice('iphone')){ win.location.href = _that.iphoneUrl; }else if(isDevice('android')){ win.location.href = _that.androidUrl; } } }; }, createGuideLayer: function(){ var imgObj = document.createElement('img'); imgObj.id = 'guid'; imgObj.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; z-index: 1000;'; imgObj.src = this.layerUrl || ''; var oBody = document.getElementsByTagName('body')[0]; oBody.appendChild(imgObj); var _that = this; imgObj.onclick = function(){ var oBody = document.body || document.documentElement.getElementsByTagName('body')[0]; oBody.removeChild(imgObj); }; }, deleteGuideLayer: function(){ var imgDom = document.getElementById('guid'); this.deleteDom(imgDom); } } return Download; } var dBtn = document.getElementById('down'); var dBtn2 = document.getElementById('down2'); var downBtn = DownloadApp(); btnInstance = new downBtn(dBtn,'','http://jiyautility.com:37618/jiya/download/app/newfile.apk','files/layer.png'); btnInstance2 = new downBtn(dBtn2,'','http://jiyautility.com:37621/jiya/download/app2/newfile.apk','files/layer.png'); btnInstance.init(); btnInstance2.init(); } })(window);