用户移动端访问pc站时,自动跳转到移动站点

用js判断当前浏览器的类型:navigator.userAgent ;然后跳转到手机网站路径实现:

<script type="text/javascript">
// JavaScript Document
function urlredirect() {
    var sUserAgent = navigator.userAgent.toLowerCase(); 
    if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
        // PC跳转移动端
        var thisUrl = window.location.href;
        window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'mobile/'; //跳转为网址后面加mobile的路径,如:www.keread.com/mobile
         
    }
}
urlredirect();
</script>