Search code examples
javascriptinternet-explorerinternet-explorer-7internet-explorer-6conditional-comments

How to load different scripts for different versions of IE?


I use these scripts to repair the errors in IE (Hacks).

There is one for each version.

I know that everything has IE9.js IE8 and 7 but would like to load only the necessary script to that version of the browser;

Today my code is as follows:

<!--[if lt IE 7]>
    <script src="@Url.Content("~/Scripts/IE7.js")"></script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![endif]-->

<!--[if lt IE 8]>
    <script src="@Url.Content("~/Scripts/IE8.js")">IE7_PNG_SUFFIX=".png";</script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![endif]-->

<!--[if lt IE 9]>
    <script src="@Url.Content("~/Scripts/IE9.js")"></script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![endif]-->

I would not like to use something like <!--[if eq IE 8]> because I do not know how it would behave in such versions as IE8.5.

I do not know if there is else, I searched the internet and did not see anyone commenting on this. But it would be the ideal solution.

Something like this:

<!--[if lt IE 7]>
    <script src="@Url.Content("~/Scripts/IE7.js")"></script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![elseif lt IE 8]-->
    <script src="@Url.Content("~/Scripts/IE8.js")">IE7_PNG_SUFFIX=".png";</script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![elseif lt IE 9]-->
    <script src="@Url.Content("~/Scripts/IE9.js")"></script>
    <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
<![endif]-->

I appreciate the help.


Solution

  • You do not need to include IE7/IE8.js if you are using IE9.js

    <!--[if lt IE 9]>
        <script src="@Url.Content("~/Scripts/IE9.js")"></script>
        <script src="@Url.Content("~/Scripts/ie7-squish.js")"></script>
    <![endif]-->
    

    Problem solved.