웹 브 라 우 저 접근 깨 우기 app

//         
var env = {
    agent: window.navigator.userAgent.toLowerCase(),
    platform: navigator.platform,
    openios: 'xxx://',
    openand: 'xxx://',
    iosURL: 'itms-apps://itunes.apple.com/app/idxxxxxx',
    androidURL: 'http://xxxx',
    falg: false,
    isWechat: function() {
        return this.agent.match(/MicroMessenger/i) == 'micromessenger';
    },
    isAndroid: function() {
        return this.agent.match(/android/i) == 'android';
    },
    isIphone: function() {
        return this.agent.match(/iphone/i) == 'iphone';
    },
    isIpad: function() {
        return this.agent.match(/ipad/i) == 'ipad';
    },
    isPc: function () {
        if(this.platform.indexOf("Win") == 0 || this.platform.indexOf("Mac") == 0){
            return true
        }
    },
    init: function() {
        if (env.isWechat()) {
            //       
            // $(".aatips").show()
        } else if (env.isIphone()) {
            //  appstore
            window.location.href = env.iosURL;

        } else {
            window.location.href = env.androidURL;
        }
    }
}
$(function() {
    if(typeof(Storage)!=="undefined")
    {
        try {
        localStorage.setItem('localStorage', 1);
        localStorage.removeItem('localStorage');
    } catch (e) {
        Storage.prototype._setItem = Storage.prototype.setItem;
        Storage.prototype.setItem = function() {};
        alert('               ,         。');
    }
        var aclose = sessionStorage.getItem("aclose");
        var iarouse = sessionStorage.getItem("iarouse");

        if(!env.isWechat() && !env.isIpad() && !env.isPc()  &&  aclose == null ){
            aashow();
        }
        if(iarouse == null && !env.isIpad()){
            //              
            if (env.isIphone()) {
                window.location.href = env.openios;
                sessionStorage.setItem("iarouse", "yes");
            } else if (env.isAndroid()) {
                window.location.href = env.openand;
                sessionStorage.setItem("iarouse", "yes");
            };
        }
        //        
        $(".aaclose").click(function(){
            aaclose();
            sessionStorage.setItem("aclose", "yes");
        })
    } else {
        $(".aaclose").click(function(){
            aaclose();
        })
    };
    function downApp(){
        if (env.isIphone()) {
            window.location.href = env.openios;
        }else {
            window.location.href = env.openand;
        }
        $(document).on('visibilitychange webkitvisibilitychange',function(){
            env.falg = true;
        });
    }
//        
    $(".aa-down").click(function(){
        downApp();
        var timer = setTimeout(function(){
            if (!env.falg){
                //  
                $(document).unbind( "visibilitychange webkitvisibilitychange")
                env.falg = false;
                if (env.isIphone()) {
                    window.location.href = env.iosURL;
                } else {
                    window.location.href = env.androidURL;
                }
            }
        },2000);
    })
})

좋은 웹페이지 즐겨찾기