pc网站自动跳转到移动终端网站

function uaredirect(murl){
    try {
        if(document.getElementById("bdmark") != null)
        {
            return;
        }
        var noredirect = document.location.search;
        if (noredirect.indexOf("no_redirect=true") < 0){
            if ((navigator.userAgent.match(/(iPhone|iPod|BlackBerry|Android.*Mobile|webOS|Windows CE|IEMobile|Opera Mini|Opera Mobi|HTC|LG-|LGE|SAMSUNG|Samsung|SEC-SGH|Symbian|Nokia|PlayStation|PLAYSTATION|Nintendo DSi)/i)) ) {
                    location.replace(murl);
            }
        }    
    }
    catch(err){}
}


使用方法:
<script type="text/javascript">uaredirect("http://3g.ifeng.com");</script>
原文地址:https://www.cnblogs.com/daly2008/p/2891898.html