HTML: How to force IE11 to emulate IE9 in HTML?

2019-06-13 16:34发布

问题:

How to force IE11 in html to use IE9 css styles.

I used this code

<script runat="server">
        private void Page_PreRender(object sender, EventArgs e)
        {
            var meta = new HtmlMeta();
            meta.Content = "IE=EmulateIE9";
            meta.HttpEquiv = "X-UA-Compatible";
            this.Page.Header.Controls.AddAt(0, meta);
        }
</script>

or

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

To get the same stylres when is internet explorer for all versions, taking ie9 as standard.

I am doing this code:

<!--[if IE]>
        <link rel="stylesheet" type="text/css" href="~/App_Themes/CocktailSite/master-interno-ie.css" media="screen" />
   <!--[else]>
        <link rel="stylesheet" type="text/css" href="~/App_Themes/CocktailSite/master-interno.css" media="screen" />
<![endif]-->

it is working when is IE9 and take master-interno-ie.css but in IE11 takes master-interno.

I was wahching all answer here and not worked in my case.

回答1:

IE no longer evaluates conditional HTML comments.

As of Internet Explorer 10, conditional comments are no longer supported by standards mode. Use feature detection to provide effective fallback strategies for website features that aren't supported by the browser.



回答2:

I got it using jQuery.

between scripts and link i coded this:

function isIE() {
    var sAgent = window.navigator.userAgent;
    var Idx = sAgent.indexOf("MSIE");

    // If IE, return version number.
    if (Idx > 0) return true;    
    // If IE 11 then look for Updated user agent string.
    else if (!!navigator.userAgent.match(/Trident\/7\./)) return true;
    else return false; //It is not IE
}

After it I aded:

if (isIE()) {
    jQuery('head').append('<link rel="stylesheet" type="text/css"     href="~/App_Themes/CocktailSite/master-interno-ie.css" media="screen" />');
}     

it is working for my neededs.

TESTED FOR ALL IE versions, CHROME AND FIREFOX