天天看點

html+js實作判斷不同裝置跳轉不同頁面

簡介

js代碼

<script type="text/javascript">  
var userAgent = navigator.userAgent.toLowerCase();
    var platform;
    if(userAgent == null || userAgent == ''){
        platform = 'WEB' ; 
    }else{
        if(userAgent.indexOf("android") != -1 ){ 
            platform = 'ANDROID';
            location.href = "http://2bbt.com/";
        }else if(userAgent.indexOf("ios") != -1 || userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1){ 
            platform = 'IOS';
            location.href = "http://2bbt.com/";
        }else if(userAgent.indexOf("windows phone") != -1 ){ 
            platform = 'WP';
            location.href = "http://2bbt.com/";
        }else{
            platform = 'WEB' ;
            location.href = "http://2bbt.com/pc";
        }
    }
</script>