首页 文章

检测到IE 9兼容模式时显示警告

提问于
浏览
1

我想在IE9中检测兼容模式并向用户显示警告消息 .

我的兼容性视图设置是“以兼容模式显示所有网站” . 但是,IE9仍然没有这种情况 .

if(navigator.userAgent.indexOf("MSIE 7.0") > 0 && navigator.userAgent.indexOf("Trident/5.0") > 0).

我可以从F12选项验证我在IE 9兼容模式下 . 当我打印navigator.userAgent时,它显示MSIE 9.0 .

但是,从F12选项,如果我从compatbility模式更改为普通模式然后再比较模式,我可以看到userAget具有MSIE 7.0并且条件变为true .

怎么解决?

如果我们在IE9兼容模式下打开它,是否有任何网站上显示此类警告?

1 回答

  • 0

    对XPath API,用户代理子串和窗口属性使用组合测试来识别IE9兼容模式:

    //IE XPath API
    if (!!window.XPathEvaluator === false && !!window.XPathExpression === false)
      {
      //Compatibility Mode
      if(/compatible/.test(navigator.userAgent) )
        {
        //IE9 innerWidth property exists, but IE10 matchMedia property does not
        if(!!window.innerWidth && !window.matchMedia)
          {
          alert("IE9 compatibility mode");
          }
        }
      }
    

相关问题