IF IE条件不工作 [英] IF IE conditionals not working

查看:185
本文介绍了IF IE条件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力争取获得评论条件,我没有运气,有人可以解释我做错了什么?

I have been driving myself nuts trying to get comment conditionals to work and I'm not having any luck can someone explain what I'm doing wrong?

这里是我的代码:

        <!--[if IE 10]>
            IE IS VERSION 10<br />
        <![endif]-->
        <!--[if !IE]><!-->
            Browser is not IE
        <!--<![endif]-->
        <!--[if lt IE 9]>
            IE IS LESS THAN VERSION 9<br />
        <![endif]-->

发生的是令人沮丧的不一致。当我在 IE8 中加载上述代码的网页时,会显示IE IS LESS THAN VERSION 9对不对?没有,因为当我在 IE10 中加载相同的网页时,我收到了浏览器不是IE

What is happening is frustratingly inconsistant. When I load the page with the above code in IE8 it get the message "IE IS LESS THAN VERSION 9" Great right? No because when I load the SAME PAGE in IE10 I get the message "Browser is not IE"

它认为IE10不是一个IE浏览器?我一直在页面后抓取页面,但似乎没有任何问题,我的代码从我发现。

Why does it think that IE10 is not an IE browser?! I've been crawling page after page but there doesn't seem to be any thing wrong with my code from what I've found.

推荐答案

IE 10不支持条件语句。

IE 10 does not support conditional statements.

Internet Explorer 10中的条件语句。它会将条件注释视为常规HTML注释,并完全忽略。

Conditional statements in Internet Explorer 10.. It will treat conditional comments as regular HTML comments, and ignored entirely.

如果您需要定位IE10,请访问跨浏览器最佳做法 - 使用功能检测库,例如 Modernizr 而不是浏览器检测。

If you need to target IE10, go for Cross browser best practises — use a feature detection library such as Modernizr instead of browser detection.

在此中找到了 impresswebs 的解决方案href =http://www.impressivewebs.com/ie10-css-hacks/#comment-27811>意见:

found a solution on impressivewebs in this comment:

这是测试

解决方案是:

if (Function('/*@cc_on return document.documentMode===10@*/')()) {
    alert('IE 10');
} else {
    alert('Not IE 10');
}

It


  • 不需要条件注释;

  • 即使进行评论剥离压缩/处理也可以工作;

  • Internet兼容模式;

  • 更多可能符合互联网  Explorer  11;
  • 不需要独立的脚本标记(只需添加到其他JavaScript代码中)。
  • 不需要jQuery测试

  • doesn’t need conditional comments;
  • works even if comment stripping compression/processing;
  • no ie10 class added in Internet Explorer 11;
  • more likely to work as intended with Internet Explorer 11 running in Internet Explorer 10 compatibility mode;
  • doesn’t need standalone script tag (can just be added to other JavaScript code in the head).
  • doesn't need jQuery to test

这篇关于IF IE条件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆