Вопрос

I'm using the following code to add some conditional styles to a webpage (I use traditional conditional comments for IE 9 and down):

<?php if (stripos($_SERVER['HTTP_USER_AGENT'], 'MSIE 10')) { ?>
  <link href="/css/ie9.css" media="screen" rel="stylesheet" />
<?php } ?>

The problem is that the style sheet is still not being applied to some versions of IE 10, and definitely not IE 11 preview. Is there a way to target all versions of IE 10 and up? I've only seen formatting that uses [1-9], but [10-11] doesn't seem to be working.

Это было полезно?

Решение

Put some code in your user agent check to see if anything is being returned at all, it may be returning something other than "MSIE 10", it is possible that IE 10+ returns simply IE or some other statement. I have been using javascript to do this very same thing. (despite the cat-calls from the purists about using conditional comments)

Here is my javascript:

    function isIE(ver) 
    {
      var myNav = navigator.userAgent.toLowerCase();
      var IEVer = parseInt(myNav.split('msie')[1]);
      if ((typeof IEVer == "undefined") || (IEVer == null)) {
         IEVer = 0;
      }
      if IEVer = ver {
        return true;
      } 
      else {
        return false;
      }
    }

Then in where i'm adding stylesheets is do something like:

 if isIE(10) { do something }

Update: according to Microsoft, you should use feature detection instead of browser detection: http://msdn.microsoft.com/en-us/library/ie/hh273397%28v=vs.85%29.aspx

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top