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;
    }
})();
原文地址:https://www.cnblogs.com/binmengxue/p/5502118.html