简体   繁体   English

使用javascript强制IE9进入兼容模式

[英]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. 无论如何,只有将compat模式应用于帧,或者让帧将compat模式应用于父帧。

Was thinking if there is a javascript method to switch modes I could apply it to the parent frame from the child frame. 正在考虑是否有一个javascript方法来切换模式我可以将它从子框架应用到父框架。

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. 但是,它似乎不适用于帧,因为IE9禁用了一帧与另一帧不同的能力。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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