简体   繁体   中英

Force IE9 into compatibility mode using javascript

I have a frame that needs compatibility mode but parent frame seems to be setting it so the following tag inside the frame does nothing.

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

Is there anyway to apply compat mode to only the frame, or have the frame apply compat mode to the parent frame.

Was thinking if there is a javascript method to switch modes I could apply it to the parent frame from the child frame.

So here's what I've gathered.

The only thing that seems to work is the meta tag way.

However, it doesn't appear to work in frames as IE9 has disabled the ability of one frame to be of different type than another.

The meta tag also can't be preceded by script or link tags, only and other meta tags from what I've noticed, otherwise it fails as well.

TEST CASE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>Test test</title>
        <meta name="keywords" content="keywords, keyword, keyword phrase, etc.">
        <!--<link href="test.css" rel="stylesheet" type="text/css" />-->
        <!--<script type="text/javascript">alert('test');</script>-->
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    </head>
    <body>
        inline-block <div style="display:inline-block">test</div>
    </body>
</html>

From top of my head you can try to create meta tag and insert it in the parent frame head. I'm not sure though if that would force the emulation.

var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'X-UA-Compatible');
meta.setAttribute('content', 'IE=EmulateIE7');

parent.document.getElementsByTagName('head')[0].appendChild(meta);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM