美文网首页
js判断android和ios

js判断android和ios

作者: 耍帅oldboy | 来源:发表于2021-08-09 14:29 被阅读0次
    window.onload =function(){
    
        var browser={
            versions:function(){
                var u = navigator.userAgent,app = navigator.appVersion;
                return {
                    trident: u.indexOf('Trident') > -1, 
                    presto: u.indexOf('Presto') > -1, 
                    webKit: u.indexOf('AppleWebKit') > -1,
                    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
                    mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/),
                    ios: !!u.match(/(i[^;]+;(U;)? CPU.+Mac OS X)/),
                    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
                    iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1,
                    iPad: u.indexOf('iPad') > -1,
                    webApp: u.indexOf('Safari') == -1
                }
            }()
        }
        
        if(browser.versions.ios){
            //alert("苹果手机");
            var img = document.createElement("img");
            img.src = "images/app-asbdpos-bg.png";
            img.style.width = "100%";
            document.body.appendChild(img);
            setTimeout("window.location.href='https://xxxxxxx'",3000)
        }
        
        if(browser.versions.android){
            //alert("安卓手机");
            var img = document.createElement("img");
            img.src = "images/app-asbdpos-bg.png";
            img.style.width = "100%";
            document.body.appendChild(img);
                var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            return;
        }else{
            setTimeout("window.location.href='https://xxxx'",3000)
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:js判断android和ios

          本文链接:https://www.haomeiwen.com/subject/zyyzvltx.html