屏幕宽度检测在internet explorer中不起作用

Screen width detection is not working in internet explorer

本文关键字:explorer 不起作用 internet 检测 屏幕      更新时间:2023-09-26

我有以下脚本,用于确定访问页面的设备的屏幕宽度。这适用于除ie之外的所有浏览器。有人认为这是怎么回事或为什么不起作用吗?

function view() {
    var isMobile = window.matchMedia("only screen and (max-width: 760px)");
   if (isMobile.matches) {
        //Do Nothing
    }
    else
    {
    horizontalview();
    }
}

使用jQuery 轻松

$(document).ready(function() {
  var isMobile = false;
  if ($(window).width() < 768) {
    isMobile = true;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>