Why doesn't Internet Explorer 11 honour conditional comments even when emulating Internet Explorer 8 document mode?

41,726

Solution 1

According to Jacob Rossi [MSFT]

This should be fixed in Update 1 for IE11, released last week.

That was posted on April 22, 2014.

In running a few tests myself it does appear that this was fixed and all is running smoothly again for testing the most amazing browser ever produced...Internet Explorer!

Solution 2

I just tried using this in Internet Explorer 11 on Windows 7 to make sure my used HTML5 semantic elements were being created for Internet Explorer 8 and below (via conditional comments), and the browser simply ignores them. -_-

This feature worked perfectly fine in Internet Explorer 10, and Microsoft just had to tinker with it, didn't they?

<!--[if lte IE 8]><script src="ie8-html5.js"></script><![endif]-->

Apart from this, I'm actually enjoying Internet Explorer, which makes for a change.

Solution 3

This worked for me and seems like the most elegant/easy fix (Internet Explorer 10 and Internet Explorer 11 I guess are the only browsers that support -ms-high-contract):

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {  
   /* IE10+ specific styles go here */
}

Solution 4

I have another solution for this.

Internet Explorer 11 with Internet Explorer 8 compatibility mode turned on contains the string 'MSIE 8.0', so:

(PHP example)

if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0') !== false) {
    $head[] = sprintf('<link rel="stylesheet" href="ie8.css" />');
}

Solution 5

I recently ran into the same problem. I also found that some conditional comments work:

  • gt and lt worked fine
  • gte and lte never worked

So one potential solution would be to change the conditional statements to use the gt and lt operators.

The other alternative, which I found more useful, was to use a service like browserstack.

Share:
41,726

Related videos on Youtube

thasmo
Author by

thasmo

Updated on April 16, 2020

Comments

  • thasmo
    thasmo about 4 years

    I'm using the new Internet Explorer 11 developer tools to switch the document mode to "8", but conditional comments are still ignored, that is, they are not properly parsed and behave like normal comments. So any referenced file inside the conditional comment is not requested/loaded by the browser.

    Why does this happen? Is it a bug?

    If you think that this is indeed a bug that needs to be fixed, please go in and say that you too can reproduce this on the Microsoft bug report that is reported for this issue:
    Conditional comments do not work when emulating document modes via F12 Developer Tools.

    Update: This issue has been reported to be fixed in the mentioned bug report.

    • Alexander Rechsteiner
      Alexander Rechsteiner over 10 years
      Asking myself the same question! I know they dropped the conditional comments in IE10 but IMHO the emulator should consider them when testing for older browsers.
    • thasmo
      thasmo over 10 years
      Indeed, that makes the feature unusable.
    • Spudley
      Spudley over 10 years
      The real question is why are you using compatiblity mode? My advice is to avoid compat mode like the plague. It certainly isn't suitable for testing, regardless of the issue you've described, as there are known bugs and quirks with it that go all the way back to when they first introduced compat mode. If you're testing for backward compatibility, you really need to use a real copy of IE8 (and IE9, etc). Go to modern.ie and download the VMs they provide for testing.
    • Evgeny
      Evgeny over 10 years
      There is a bug open on IE bug tracker. I encourage everyone to visit and tell Microsoft that you can reproduce this. connect.microsoft.com/IE/feedback/details/806767/…
    • Rolf
      Rolf over 10 years
      I think using compatibility mode for testing makes more sense than downloading a 1/2 gigabyte or so image for every browser. So there are bugs, (and this is probably one of them), but 99.% of the time it just works.
    • user2012801
      user2012801 about 10 years
      Another big disadvantage of using VM is that you don't have access to Dev Tools IE11 provides even in emulator mode.
    • ClarkeyBoy
      ClarkeyBoy almost 9 years
      We use BrowserStack - it costs money, granted, but it's not that much if you're a web agency or something and it means that you can provide better service to your customers. Forget VMs - they're the past. We used to use those but they took up like 3GB on each of our machines, that's why we started looking for alternatives.
    • simon
      simon almost 9 years
      @ClarkeyBoy -- worrying about using 3GBs of space sounds like the past to me...
  • Rolf
    Rolf over 10 years
    Yes, IE 11 is a better experience, with all the animations that actually work :). Yes MS has a history of "tinkering" with stuff just when users are starting to get used to them. Look at what they did to Windows XP... "Fixing what's not broken", some people would say. Anyway that sucks
  • Adrien Be
    Adrien Be over 10 years
    Internet Explorer browsers are so bad. No consistency between versions. Who the hell developped this? even my grand ma could do a better job!
  • Adrien Be
    Adrien Be over 10 years
    EDIT: they are fixing this (or trying) since 22nd January 2014 connect.microsoft.com/IE/feedback/details/806767/…
  • DylRicho
    DylRicho over 10 years
    @AdrienBe Well, that's certainly a step in the right direction.
  • Walf
    Walf over 10 years
    Conditional comments don't rely on script, or any third party code.
  • mgutt
    mgutt about 10 years
    I've tested the document modes and it seems not to change the user agent?!
  • Andrei Konstantinov
    Andrei Konstantinov about 10 years
    @mgutt You're right. There are two options in Emulation - Document mode and User agent. Document mode changes how the browser works and how it renders the page, and User Agent change what browser telling site about browser's version. (in my example it's $_SERVER['HTTP_USER_AGENT'] variable what contains this info) So basically you need to change both this options to, for example, IE8.
  • mgutt
    mgutt about 10 years
    @ Andrew Thank you. Now I found the setting. The problem was the german translation. They translated "user agent" with "Zeichenfolge des Benutzer-Agents" and I thought this meant the charset. Some things should not be translated ;)
  • Valerio Gentile
    Valerio Gentile about 10 years
    This solution is the best. I've converted it to ASP.NET MVC Razor and it works perfectly: @{if (Request.UserAgent.Contains("MSIE 8.0")) { /*your metatag here*/ }}
  • DylRicho
    DylRicho about 10 years
    @Anthony My answer is incorrect? How so? It's basically saying what you've just said.
  • carrabino
    carrabino about 10 years
    @DylRicho ahh, i missed where you said "simply ignores them". Yes, i can confirm that ie11 ignores them.
  • Tek
    Tek almost 10 years
    This needs to be upvoted more. I had to dig through two stack overflow answers just to get here.
  • Kohjah Breese
    Kohjah Breese over 9 years
    Excellent, thanks. When is Microsoft going to kill this jumble?
  • El Kabong
    El Kabong over 9 years
    @Walf - true, but they're also not supported in IE. See here: msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx
  • Gino
    Gino over 9 years
    Tank for that, IE 11 do not honour old conditional methode. <!--[ if IE ]>
  • hofnarwillie
    hofnarwillie about 9 years
    @AdrienBe: Really, your grandma? Wow. What's the last browser you and your grandma developed together? I bet it's good. Granted, IE has issues, but it's a hell of a lot better than what I would do, so I don't moan about it.
  • Adrien Be
    Adrien Be about 9 years
    @hofnarwillie sigh.... I dont make car either, but should i not moan abt a car because it's crap or dangerous? Same goes for anything. I'm unhappy abt this product, i like the other ones better, and yes I think it's fine to say it. Chrome, firefox abd safari are much better. Shame on MS for producing this garbage.
  • hofnarwillie
    hofnarwillie about 9 years
    @AdrienBe I ask again: When last did you build a browser? Also, unlike a browser, a car is purchased and therefore the behavior described is paid for and then you can legally expect it to work. How much did you pay for IE?
  • Adrien Be
    Adrien Be about 9 years
    @hofnarwillie dont get me wrong, I do NOT use it, ever. However, many people do because they have zero knowledge regarding browsers or their corporate policy prevent them from installing something else. And every web project needs to throw in some extra work to support this. This discussion is going nowhere, i obviously disagree with u, if u are fine using garbage just because it's free when u have the choice for other free but good product, then fine, why not.
  • hofnarwillie
    hofnarwillie about 9 years
    @AdrienBe I never said I like it either. I just get tired of people moaning about it. It has become more of a "follow the crowd" thing. Like it's cool to complain about IE. Some people moan about it without even really knowing the pain points that IE provide. I get annoyed by it for the same reason that I dislike people who instinctively buy an iPhone purely because everyone does. Interestingly, no-one moans about the hoops that you have to jump through when doing web development for an apple product. I have found that nearly as frustrating as developing for IE.
  • Adrien Be
    Adrien Be about 9 years
    @hofnarwillie I do know far too many of IE bugs/hoops/hacks. I actually could probably do it a full time job & consult companies/team having IE-specific issues. So I might be elligible for a right to complain about IE ;) Fair enough, I never did development for apple products so can't comment about that. I suppose the main reason we hear so much about IE is proportional to the amount of people forced to develop & use this product.
  • Mohamed Hussain
    Mohamed Hussain about 9 years
    @Lynda: Could you post your IE11 version ? mine is11.0.9600.17631
  • L84
    L84 about 9 years
    @MohamedHussain - My version is 11.0.9600.17690IC.
  • paddotk
    paddotk about 9 years
    But visitors of your website would have to do the same to get the same result. Making it useless.
  • paddotk
    paddotk about 9 years
    You MUST be saracastic.
  • paddotk
    paddotk about 9 years
    About IE being the 'most amazing browser'?
  • L84
    L84 about 9 years
    @poepje - You don't consider IE the most amazing browser? I'm shocked! Just kidding. My comment, ...the most amazing browser ever produced...Internet Explorer! was meant to be taken sarcastically as you saw. =>
  • paddotk
    paddotk about 9 years
    Hehe. Thanks for the link to the article.
  • Just Plain High
    Just Plain High about 9 years
    Yes. But this is for if you are testing older versions of IE through IE11 developer tools. So using IE11 but running as IE8, the conditional comments will not work. For someone actually using IE8, the conditional comments will work. Probably ^_^
  • Drew
    Drew over 8 years
    This site is a handy reference for what all the permutations of user agent strings look like: useragentstring.com/pages/Internet%20Explorer