【问题标题】:Screen width detection is not working in internet explorer屏幕宽度检测在 Internet Explorer 中不起作用
【发布时间】:2015-11-15 20:03:54
【问题描述】:

我有以下脚本用于确定访问页面的设备的屏幕宽度。这适用于所有浏览器,除了即有没有人有任何想法如何或为什么不工作?

function view() {
    var isMobile = window.matchMedia("only screen and (max-width: 760px)");

   if (isMobile.matches) {
        //Do Nothing
    }
    else
    {
    horizontalview();
    }
}

【问题讨论】:

    标签: javascript css width screen explorer


    【解决方案1】:

    使用 jQuery 轻松实现

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

    【讨论】:

    • 啊! - jquery 来救援。我应该知道的更好。谢谢,这解决了问题。
    猜你喜欢
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    相关资源
    最近更新 更多