当手机访问时自动跳转到手机网站

html源码

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>首页</title>
<script charset="utf-8" src="phone.js" type="text/javascript"></script>
<body>
pc版本
</body>
</html>

 

phone.js代码

if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
    if(window.location.href.indexOf("?mobile")<0){
        try{
            if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
                window.location.href="/mobileweb/";
            }else if(/iPad/i.test(navigator.userAgent)){
            }else{
                window.location.href="/mobileweb/"
            }
        }catch(e){}
    }
}

 

posted @ 2013-03-27 16:12  神马和浮云  阅读(809)  评论(0编辑  收藏  举报