免费《新手做网站视频教程》,在线观看,如果你想从零开始自己做网站,点击开始吧!

js判断浏览器的环境(pc端,移动端,还是微信浏览器)

  1. 首页
  2. »
  3. 图文教程
  4. »
  5. 网站维护教程
  6. »
  7. js判断浏览器的环境(pc端,移动端,还是微信浏览器)

文章目录

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script type="text/javascript">
    //平台、设备和操作系统
    var system = {
        win: false,
        mac: false,
        xll: false,
        ipad: false
    };
    //检测平台
    var p = navigator.platform;
    system.win = p.indexOf("Win") == 0;
    system.mac = p.indexOf("Mac") == 0;
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
    system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
    if (system.win || system.mac || system.xll || system.ipad) {
        alert("请手机端访问本站!网址 www.douyanwangluo.xyz");
    } else {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            // alert("在手机端微信上打开的");
            window.location.href = "https://www.xuezuowangzhan.cn/";
        } else {
            // alert("在手机上非微信上打开的");
            window.location.href = "https://www.xuezuowangzhan.cn/";
        }
    }
</script>

推荐阅读

联系我