使用 Javascript 更改 IE 文档模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5317528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change IE Document Mode with Javascript?
提问by Sam
Is it possible to change the IE document mode with Javascript? I won't get into the nitty-gritty details here, but I'm fighting with a locked down Drupal site that will not allow me any acces to edit the theme files. Obviously, the correct thing to do would be to write something into the head, like this:
是否可以使用 Javascript 更改 IE 文档模式?我不会在这里详细介绍细节,但我正在与一个锁定的 Drupal 站点作斗争,该站点不允许我对编辑主题文件的任何访问权限。显然,正确的做法是在头部写入一些内容,如下所示:
<meta http-equiv="X-UA-Compatible" content="IE=8">
But, as I mentioned, I have no access to that part of the page, so I'm hoping that I can use Javascript... sort of like this:
但是,正如我提到的,我无法访问页面的那部分,所以我希望我可以使用 Javascript ......有点像这样:
document.getElementsByTagName('head')[0].appendChild('<meta http-equiv="X-UA-Compatible" content="IE=IEVersion">');
Sadly, this doesn't work.
可悲的是,这行不通。
采纳答案by Michael McTiernan
That's a bit of a pickle you're in. What about this?
这有点像泡菜。这个怎么样?
if (navigator.userAgent.indexOf("MSIE 7.0")) {
// add conditional css in here
} else {
// default css
}