让页面判断手机端访问 如果则跳转

让页面判断手机端访问 如果则跳转

<script type="text/javascript">
/*判断手机端访问*/
var isMobile = {
    Android: function () {
            return navigator.userAgent.match(/Android/i) ? true : false;
        },
        BlackBerry: function () {
            return navigator.userAgent.match(/BlackBerry/i) ? true : false;
        },
        iOS: function () {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
        },
        Windows: function () {
            return navigator.userAgent.match(/IEMobile/i) ? true : false;
        },
        any: function () {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
        }
};
if (!isMobile.any()) {
    window.location.href = "http://www.baidu.com/";
}
</script>

 

 

强制让网页适配成移动端尺寸

<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /> 

 

posted @ 2025-06-06 16:04  asqq8  阅读(8)  评论(0)    收藏  举报