@njy
2017-01-03T01:46:45.000000Z
字数 4431
阅读 1882
新浪彩通
function adjustBase() {var clientWidth = util.viewData().viewWidth;var clientHeight = util.viewData().viewHeight;if (clientWidth > 500) {clientWidth = 500;}$("body").width(clientWidth);$("body").height(clientHeight);}adjustBase();window.onresize = function(){adjustBase();}// 微信遮罩提示if (window.navigator.userAgent.toLowerCase().indexOf('micromessenger') >= 0) {window.$wxbox = $("#ct0_wx_box");if($wxbox.length>0){$wxbox.show();$wxbox.on("click",function(){$wxbox.hide();})}}window.popup = {show: function($layout) {var $mask = $("#ct0_mask_full");var $popup_box = $(".ct0_popup");var viewData = util.viewData();var layout = $layout[0];document.body.style.overflow = 'hidden';$popup_box.hide();$layout.show();layout.style.visibility = "hidden";var cHeight = layout.offsetHeight;layout.style.marginTop = (viewData.viewHeight / 2 - cHeight / 2 - 60) + 'px';$mask.show();layout.style.visibility = "visible";},maskShow: function() {document.body.style.overflow = 'hidden';var $mask = $("#ct0_mask_full");$mask.show();},hide: function() {var $mask = $("#ct0_mask_full");var $popup_box = $(".ct0_popup");document.body.style.overflow = 'auto';$mask.hide();$popup_box.hide();},alert: function(msg, callback) {var self = this;var $popup_alert = $("#popup_alert");$("#popup_alert_txt").html(msg);popup.show($popup_alert);callback && callback();}}window.h5OpenApp = function(){// android下载地址// var aphoneDLink = "http://wap.133.cn/download/FlightManager-BMoaweb.apk";var aphoneDLink = "http://n.sinaimg.cn/sports/lottpao/v120/app/caitong_v1.0_caitong_release.apk";// schemevar schemeDLink = "lotterylaunch://com.sina.lottery.gai/open";// ios下载地址// var iphoneDLink = "https://itunes.apple.com/cn/app/zhi-fu-bao-rang-sheng-huo/id333206289?mt=8&v0=WWW-GCCN-ITSTOP100-FREEAPPS&l=&ign-mpt=uo%3D4";// 应用宝下载地址// var imttDLink = "http://imtt.dd.qq.com/16891/9033AE4E61B3A7ECB6F36298AC651976.apk?fsname=com.flightmanager.view_6.2_117.apk&csr=4d5s";var browser = {versions: function() {var u = navigator.userAgent;return {mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)qq: u.match(/\sQQ/i) == " qq", //是否QQtrident: u.indexOf('Trident') > -1, //IE内核presto: u.indexOf('Presto') > -1, //opera内核webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器iPad: u.indexOf('iPad') > -1, //是否iPadwebApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部};}()}window.bv = browser.versions;function openApp(openUrl, appUrl) {//检查app是否打开function checkOpen() {var _clickTime = +(new Date());function check(elsTime) {if (elsTime > 3000 || document.hidden || document.webkitHidden) {// alert("调用app成功");} else {window.location.href = appUrl;}}//启动间隔20ms运行的定时器,并检测累计消耗时间是否超过3000ms,超过则结束var _count = 0,intHandle;intHandle = setInterval(function() {_count++;var elsTime = +(new Date()) - _clickTime;if (_count >= 100 || elsTime > 3000) {clearInterval(intHandle);check(elsTime);}}, 20);}//在iframe 中打开APPvar ifr = document.createElement('iframe');ifr.src = openUrl;ifr.style.display = 'none';checkOpen();document.body.appendChild(ifr);setTimeout(function() {document.body.removeChild(ifr);}, 2000);}$("#xiaopaoDownload").on('click', function(e) {// e.preventDefault();if(bv.weixin || bv.qq){if(window.$wxbox){$wxbox.show();} else {window.$wxbox = $("#ct0_wx_box");if($wxbox.length>0){$wxbox.show();$wxbox.on("click",function(){$wxbox.hide();})}}// 腾讯应用宝页面// var msg = '<div class="popup_p1">请在浏览器打开页面下载</div>';// popup.alert(msg);// if(bv.ios || bv.iPhone || bv.iPad){// window.location.href = iphoneDLink;// } else {// window.location.href = imttDLink;// }} else if(bv.ios || bv.iPhone || bv.iPad){//ios// window.location.href = iphoneDLink;// setTimeout(function() {// location.href = 'http://lotto.sina.cn/ai/app/download.d.html';// }, 250);// setTimeout(function() {// location.reload();// }, 1000);var msg = '<div class="popup_p1">请期待ios版小炮APP</div>';popup.alert(msg);} else if(bv.android || bv.mobile){//androidopenApp(schemeDLink,aphoneDLink);} else {var msg = '<div class="popup_p1">请使用手机访问下载</div>';popup.alert(msg);// location.href = 'http://lotto.sina.cn/ai/app/download.d.html';}})var $mask = $("#ct0_mask_full");$mask.length>0 && $mask.bind("touchmove", function(e) {e.preventDefault();return false;});$("#popup_alert").on("click", function(){popup.hide();return false;});}window.h5OpenApp();
另外,可以通过 document.hidden 或 document.[webkit|moz|ms]Hidden 来判断页面是否被置入后台(即应用被唤起),或visibilitychange事件,但对于Android 4.4版本一下则不支持。