js跳轉手機端


<script>
    var host = window.location.protocol+'//'+window.location.host+'/'; //獲取當前域名
    var host_wap = window.location.protocol+'//'+window.location.host+'/wap/'; //要跳轉的手機端地址,這里寫的是wap/

    console.log(host)
    console.log(host_wap)

    //電腦端跳轉手機端
    var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "UCBrowser", "skyfire");
    var browser = navigator.userAgent.toLowerCase();
    var isMobile = false;
    for (var i=0; i<mobileAgent.length; i++){
        if (browser.indexOf(mobileAgent[i])!=-1){
            isMobile = true;
            //alert(mobileAgent[i]);
            var url = window.location.href;
            location.href =url.replace( host, host_wap );//跳轉手機端的網址
            break;
        }
    }
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM