天天看點

JS 判斷是手機端 PC端裝置

//需要在手機端才能識别為手機裝置

<script type="text/javascript"> 
    //平台、裝置和作業系統 
    var system ={ 
        win : false, 
        mac : false, 
        xll : false
    };
    //檢測平台
    var p = navigator.platform; 
    system.win = p.indexOf("Win") == 0; 
    system.mac = p.indexOf("Mac") == 0; 
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
    if(system.win||system.mac||system.xll){   
       // window.location.href="pc端通路的連結" target="_blank" rel="external nofollow" ;   
       
    console.log('pc端');

    }else{ 

window.location.href="m/index.html" target="_blank" rel="external nofollow" ;

    }

</script>
           

繼續閱讀