treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Conditional for IE9

  • Hi guys!
    I use a flashfallback exclusively for IE-users on my HTML 5 website that contains video in a -Element:


    <?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { ?>
    <script type="text/javascript" src="flashfallbackscript.js"></script>
    <video src="video/foo.m4v"></video>

    <?php } else { ?>

    <video>
    <source src="video/foo.m4v" type="video/m4v">
    <source src="video/foo.ogv" type="video/ogg">
    </video>

    <?php } ?>


    It has worked pretty good. With IE9 things are getting more complicated. I want to exclude IE9 which is capable of HTML 5 from the if-area but keep the fallback for visitors with Windows XP, i.e. IE <= 8. My PHP is poor. Can anyone help me?<br />
    Thanks alot.
    Runa
  • You can wrap it in this HTML:
    <!--[if lt IE 9]>
    <script type="text/javascript" src="flashfallbackscript.js"></script>
    <video src="video/foo.m4v"></video>
    <![endif]-->
  • Okay, I should have mentioned that the simplest way doesn't work out. There will remain two video-elements in the DOM then. The other one cannot be removed so easily. There will be no video neither in IE8 nor IE9 then.
  • Here are all the ways to target IE. The last one rocks. http://www.visibilityinherit.com/code/target-ie.php
  • I don't get why you can't do that. You above code can be achieved in html by doing this:
    <!--[if lt IE 9]>
    <script type="text/javascript" src="flashfallbackscript.js"></script>
    <video src="video/foo.m4v"></video>
    <![endif]-->

    <!--[if (gte IE 9)|!(IE)]><!-->
    <video>
    <source src="video/foo.m4v" type="video/m4v">
    <source src="video/foo.ogv" type="video/ogg">
    </video>
    <!--<![endif]-->