js判断web登录的是手机端还是pc端

来源:互联网 发布:origin图中点显示数据 编辑:程序博客网 时间:2024/05/16 01:17

网上很多代码。。。试了很多,不管用,其中一个有用,记录下来!!

<script type="text/javascript">        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="http://www.bqkeji.com/mobile";//手机端网址                    }else if(/iPad/i.test(navigator.userAgent)){                    }else{                        window.location.href="http://www.bqkeji.com";//pc端网址                    }                }catch(e){}            }        }    </script>

只需要写在pc端的index页面的head 里即可。

1 0