JavaScript判断移动端及pc端访问不同的网站

(function () {
    var url = location.href;
    // replace www.test.com with your domain
    if ( (url.indexOf('www.test.com') != -1) && navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i) ) {
        var newUrl = url.replace('http://www', 'http://m');
        location.href = newUrl;
    }
})();

 

posted @ 2016-05-17 16:18  归尘2016  阅读(177)  评论(0编辑  收藏  举报