覆盖内网兼容模式IE8

发布于 2024-08-26 09:15:15 字数 83 浏览 8 评论 0原文

默认情况下,IE8 强制 Intranet 网站进入兼容模式。我尝试将元标头更改为 IE8,但它不承认元标头,仅使用浏览器设置。有谁知道如何禁用此功能?

By default IE8 forces intranet websites into compatibility mode. I tried changing the meta header to IE8, but it doesn't acknowledge the meta header and just uses the browser setting. Does anyone know how to disable this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

青春有你 2024-09-02 09:15:15

可以覆盖 Intranet 中的兼容模式。

对于 IIS,只需将以下代码添加到 web.config 中。为我工作,使用 IE9。

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <clear />
      <add name="X-UA-Compatible" value="IE=edge" />
    </customHeaders>
  </httpProtocol>
</system.webServer> 

相当于 Apache:

Header set X-UA-Compatible: IE=Edge

对于 nginx:

add_header "X-UA-Compatible" "IE=Edge";

对于express.js:

res.set('X-UA-Compatible', 'IE=Edge')

It is possible to override the compatibility mode in intranet.

For IIS, just add the below code to the web.config. Worked for me with IE9.

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <clear />
      <add name="X-UA-Compatible" value="IE=edge" />
    </customHeaders>
  </httpProtocol>
</system.webServer> 

Equivalent for Apache:

Header set X-UA-Compatible: IE=Edge

And for nginx:

add_header "X-UA-Compatible" "IE=Edge";

And for express.js:

res.set('X-UA-Compatible', 'IE=Edge')
旧瑾黎汐 2024-09-02 09:15:15

Michael Irigoyen 是正确的,但它有点复杂......

如果您使用 Paul Irish 的精彩样板,那么您将得到如下所示的内容:-

<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

这不会按预期工作并强制 IE 进入兼容模式 < strong>Intranet 环境(如果您选中了“在兼容性视图中显示 Intranet 站点”)。您需要删除条件 IE 注释以阻止 Intranet 兼容模式。

因此,以下代码将起作用:

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

基本上,如果您在 之前触发条件 IE 注释如果您使用默认设置运行 IE9,那么您将在 Intranet 环境中被迫进入兼容模式。

更新 - 其他信息: 但请注意,有一个技巧可以使 HTML5 样板正常工作:

在 DOCTYPE 之前添加一个空的条件注释。另请注意,当您这样做时,您还可以在 X-UA-Compatible 指令周围添加条件注释,从而使页面 HTML5 也有效。例如:

<!--[if HTML5]><![endif]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

博客文章受到这个答案第一部分的启发,有更多细节。 顺便说一句:正如该博文中提到的,还可以将 DOCTYPE 之前的条件注释替换为带有无条件半条件注释>:。因此,像这样:

<!--[]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

但请注意,后一个变体(<--[]--><!DOCTYPE html>)将如另一个问题的答案,激活众所周知的问题 - 对于遗留问题不支持 X-UA-Compatioble 的 IE 版本(即:适用于 IE7 和 IE6)——使浏览器进入怪异模式。

Michael Irigoyen is correct BUT it is a little more complicated...

if you are using the wonderful boilerplate by Paul Irish then you will have something like the following:-

<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

This will NOT work as expected and force in IE into compatibility mode in an Intranet environment if you have the "Display intranet sites in compatibility view" checked. You need to remove the conditional IE comments to prevent Intranet compatibility mode.

So the following code will work:

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Basically if you trigger conditional IE comments before the <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> statement then you will be forced into compatibility mode in an Intranet environment if you are running IE9 with the default settings.

UPDATE — ADDITIONAL INFO: But note that there is a trick that will make the HTML5 boilplate work:

Add an emtpy, conditional comment before the DOCTYPE. And note as well, that when you do that, then you can also add conditional comments around the X-UA-Compatible directive, making the page HTML5-valid as well. So for instance:

<!--[if HTML5]><![endif]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

A blog post that was inspired by the first part of this answer, has more detail. And by the way: As mentioned in that blog post, one can also replace the conditional comment before the DOCTYPE with a semi conditional comment with no condition: <!--[]-->. Thus, like so:

<!--[]-->
<!doctype html>
<!--[if the boilerplate conditionals goes here<![endif]-->
<head>
<!--[if !HTML5]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->

But note that the latter variant (<--[]--><!DOCTYPE html>) will, as explained e.g by this answer to another question, activate the well know problem that it — for legacy IE versions without support for the X-UA-Compatioble (read: for IE7 and IE6) — bring the browser into into quirks-mode.

徒留西风 2024-09-02 09:15:15

如果您下拉“工具”菜单并选择“兼容性视图设置”,则该对话框底部有一个设置“以兼容模式显示 Intranet 站点”。如果取消选中此项,应该可以解决问题,并且 IE 将使用基于 DOCTYPE 的模式。

If you pull down the "Tools" menu and choose "Compatibility View Settings" On that dialog at the bottom is a setting "Display intranet sites in compatibility mode". If you uncheck this that should resolve the problem and IE will use the mode based on the DOCTYPE.

只为一人 2024-09-02 09:15:15

这个问题的答案存在一定程度的混乱。

目前最重要的答案是服务器端解决方案,它在 http 标头中设置一个标志,一些评论表明使用元标记的解决方案不起作用。

我认为这篇博客文章很好地概述了如何使用兼容性元信息,根据我的经验,其工作原理如下:
http://blogs.msdn.com/b/cjacks/archive/2012/02/29/using-x-ua-known-to-create-durable-enterprise-web-applications.aspx

要点:

  • 使用meta标签设置信息,在header中都可以。meta
  • 标签优先于header。meta
  • 标签必须是第一个标签,以确保浏览器不会先确定渲染引擎基于启发式

一个重要的点(我认为很多混乱都来自这一点)是 IE 有两种“类”模式:

  1. 文档模式
  2. 浏览器模式

文档模式决定渲染引擎(网页如何渲染) 。

浏览器模式确定 IE 发送到服务器的用户代理 (UA) 字符串、IE 默认的文档模式以及 IE 如何评估条件注释。

有关文档模式与浏览器模式的更多信息,请参阅本文:http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features -for-site-developers.aspx?Redirected=true

根据我的经验,兼容性元数据将仅影响文档模式。因此,如果您依赖浏览器检测,这对您没有帮助。但如果您正在使用特征检测,这应该是正确的选择。

因此,我建议使用以下语法的元标记(在 html 页面中):

<meta http-equiv="X-UA-Compatible" content="IE=9,10" ></meta>

注意:给出您已测试过的浏览器模式列表。

该博客文章还建议不要使用 EmulateIEX。这里引用一下:

话虽这么说,我确实觉得奇怪的一件事是当应用程序
请求 EmulateIE7 或 EmulateIE8。这些模拟模式本身就是
决定。因此,您不必具体说明您想要什么,而是
要求两件事中的一件,然后确定这两件事中的哪一件
通过在代码中的其他位置查找 DOCTYPE 来进行操作(然后
尝试了解 DOCTYPE 是否会给您标准
或怪癖取决于其内容——另一个有时令人困惑的地方
任务)。我认为与其这样做,不如这样做更有意义
直接指定你想要什么,而不是给出这样的回应
本身就是一个问题。如果你想要 IE7 标准,那么使用 IE=7,而不是
比 IE=EmulateIE7。 (请注意,这并不意味着您不应该使用
DOCTYPE – 你应该。)

There is a certain amount of confusion in the answers to this this question.

The top answer is currently a server-side solution which sets a flag in the http header and some comments are indicating that a solution using a meta tag just doesn't work.

I think this blog entry gives a nice overview of how to use compatibility meta information and in my experience works as described:
http://blogs.msdn.com/b/cjacks/archive/2012/02/29/using-x-ua-compatible-to-create-durable-enterprise-web-applications.aspx

The main points:

  • setting the information using a meta tag and in the header both works
  • The meta tag takes precedence over the header
  • The meta tag has to be the first tag, to make sure that the browser does not determine the rendering engine before based on heuristics

One important point (and I think lots of confusion comes from this point) is that IE has two "classes" of modes:

  1. The document mode
  2. The browser mode

The document mode determines the rendering engine (how is the web page rendered).

The Browser Mode determines what User-Agent (UA) string IE sends to servers, what Document Mode IE defaults to, and how IE evaluates Conditional Comments.

More on the information on document mode vs. browser mode can be found in this article: http://blogs.msdn.com/b/ie/archive/2010/06/16/ie-s-compatibility-features-for-site-developers.aspx?Redirected=true

In my experience the compatibility meta data will only influence the document mode. So if you are relying on browser detection this won't help you. But if you are using feature detection this should be the way to go.

So I would recommend using the meta tag (in the html page) using this syntax:

<meta http-equiv="X-UA-Compatible" content="IE=9,10" ></meta>

Notice: give a list of browser modes you have tested for.

The blog post also advices against the use of EmulateIEX. Here a quote:

That being said, one thing I do find strange is when an application
requests EmulateIE7, or EmulateIE8. These emulate modes are themselves
decisions. So, instead of being specific about what you want, you’re
asking for one of two things and then determining which of those two
things by looking elsewhere in the code for a DOCTYPE (and then
attempting to understand whether that DOCTYPE will give you standards
or quirks depending on its contents – another sometimes confusing
task). Rather than do that, I think it makes significantly more sense
to directly specify what you want, rather than giving a response that
is itself a question. If you want IE7 standards, then use IE=7, rather
than IE=EmulateIE7. (Note that this doesn’t mean you shouldn’t use a
DOCTYPE – you should.)

幸福还没到 2024-09-02 09:15:15

尝试这个元标记:

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

即使选中“在兼容性视图中显示 Intranet 站点”[无论是 Intranet 还是所有网站],它都应该强制 IE8 呈现为 IE8 标准模式,我在 IE 8.0.6 上亲自尝试过

Try this metatag:

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

It should force IE8 to render as IE8 Standard Mode even if "Display intranet sites in compatibility view" is checked [either for intranet or all websites],I tried it my self on IE 8.0.6

眉目亦如画i 2024-09-02 09:15:15

我们的系统管理员通过为我们的组织全局取消选中该框解决了此问题。用户甚至不需要注销。

在此处输入图像描述

Our system admin resolved this issue by unchecking the box globally for our organization. Users did not even need to log off.

enter image description here

吲‖鸣 2024-09-02 09:15:15

我找到了一个有效的答案,允许覆盖检查的内联网兼容性视图。
只需在页面的 OnInit 事件中添加此行(不需要 meta 或 web.config customHeader):

Response.AddHeader("X-UA-Compatible", "IE=EmulateIE8");

I found a working answer that allow to override the checked Intranet Compatibility View.
Just add in the OnInit event of your page this line (no meta or web.config customHeader need):

Response.AddHeader("X-UA-Compatible", "IE=EmulateIE8");
看海 2024-09-02 09:15:15

尝试将以下内容放入标题中:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Paul Irish 的 HTML5 Boilerplate 提供(但它也适用于 XHTML Transitional)。

Try putting the following in the header:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Courtesy Paul Irish's HTML5 Boilerplate (but it works in XHTML Transitional, too).

孤芳又自赏 2024-09-02 09:15:15

我能够通过将元标记指定为头部分中的 THE FIRST TAG 来覆盖兼容模式,而不仅仅是第一个元标记,而是作为且仅作为 VERY FIRST TAG

感谢@stefan.s 的精彩回答让我明白了这一点。在阅读之前,我有:

这不起作用

<head> 
<link rel="stylesheet" type="text/css" href="/qmuat/plugins/editors/jckeditor/typography/typography.php"/>
<meta http-equiv="x-ua-compatible" content="IE=9" >

,将链接标记移开,它起作用了

这有效

<head><meta http-equiv="x-ua-compatible" content="IE=9" >

因此,设置为使用兼容性的 IE8 客户端将页面呈现为 IE8 标准模式 - 内容='IE=9' 表示使用 IE9 及以上可用的最高标准。

I was able to override compatibility mode by specifying the meta tag as THE FIRST TAG in the head section, not just the first meta tag but as and only as the VERY FIRST TAG.

Thanks to @stefan.s for putting me on to it in your excellent answer. Prior to reading that I had:

THIS DID NOT WORK

<head> 
<link rel="stylesheet" type="text/css" href="/qmuat/plugins/editors/jckeditor/typography/typography.php"/>
<meta http-equiv="x-ua-compatible" content="IE=9" >

moved the link tag out of the way and it worked

THIS WORKS:

<head><meta http-equiv="x-ua-compatible" content="IE=9" >

So an IE8 client set to use compatibility renders the page as IE8 Standard mode - the content='IE=9' means use the highest standard available up to and including IE9.

子栖 2024-09-02 09:15:15

这不完全是一种解决方案,但我认为这是最好的解决方案。在我们的内部网站上,我们告诉人们它只能通过 Firefox 访问,我们对这里的 IE 用户并不友善。检查服务器或客户端的用户代理并拒绝他们从 IE 访问。我是一名 .NET 程序员。

This isn't exactly a solution but, I feel it is the best one. On our intranet sites we tell people it can only be accessed by Firefox, we don't take kindly to IE users around here. Check the user agent on the server or client side and deny them access from IE. And I'm a .NET programmer.

能否归途做我良人 2024-09-02 09:15:15

我一直在努力解决这个问题,并希望帮助提供独特的解决方案和见解。

某些基于 AJAX 的框架会在 的开头注入 JavaScript 和样式表,这样做似乎会阻止完善的元标记解决方案正常工作。在这种情况下,我发现直接注入 HTTP 响应标头,就像 Andras Csehi 的答案一样,可以解决问题。

然而,对于我们这些使用 Java Servlet 的人来说,解决这个问题的一个好方法是使用 ServletFilter。

public class EmulateFilter implements Filter {

@Override
public void destroy() {
}

@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
        FilterChain arg2) throws IOException, ServletException {
    HttpServletResponse response = ((HttpServletResponse)arg1);
    response.addHeader("X-UA-Compatible", "IE=8");
    arg2.doFilter(arg0, arg1);
}

@Override
public void init(FilterConfig arg0) throws ServletException {
}

}

I had struggled with this issue and wanted to help provide a unique solution and insight.

Certain AJAX based frameworks will inject javascripts and stylesheets at the beginning of the <head> and doing this seems to prevent the well-established meta tag solution from working properly. In this case I found that directly injecting into the HTTP response header, much like Andras Csehi's answer will solve the problem.

For those of us using Java Servlets however, a good way to solve this is to use a ServletFilter.

public class EmulateFilter implements Filter {

@Override
public void destroy() {
}

@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
        FilterChain arg2) throws IOException, ServletException {
    HttpServletResponse response = ((HttpServletResponse)arg1);
    response.addHeader("X-UA-Compatible", "IE=8");
    arg2.doFilter(arg0, arg1);
}

@Override
public void init(FilterConfig arg0) throws ServletException {
}

}
烟若柳尘 2024-09-02 09:15:15

我们可以在 Spring-Apache-tomcat 环境中通过在 RequestInterceptor 方法中添加一行来解决此问题 -

//before the actual handler will be executed
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {

// Some logic

// below statement ensures IE trusts the page formatting and will render it acc. to IE 8 standard.
response.addHeader("X-UA-Compatible", "IE=8"); 

return true;
}

参考自 - 如何创建过滤器并修改响应头 它涵盖了我们如何通过 RequestInterceptor (Spring) 解决这个问题。

We can resolve this problem in Spring-Apache-tomcat environment by adding one single line in RequestInterceptor method -

//before the actual handler will be executed
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {

// Some logic

// below statement ensures IE trusts the page formatting and will render it acc. to IE 8 standard.
response.addHeader("X-UA-Compatible", "IE=8"); 

return true;
}

Reference from - How to create filter and modify response header It covers how we can resolve this problem via a RequestInterceptor (Spring).

埋葬我深情 2024-09-02 09:15:15

如果您希望网站强制使用 IE 8 标准模式,请将此元标记与有效的 DOCTYPE 一起使用:

请注意“EmulateIE8”值,而不是普通的“IE8”。

根据 IE 开发人员的说法,这应该是“在 IE8 标准模式下显示标准 DOCTYPE;在 Quirks 模式下显示 Quirks DOCTYPE。使用此标签可覆盖客户端计算机上的兼容性视图并强制标准为 IE8 标准。”

有关此 IE 博客文章的更多信息: http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx

If you want your Web site to force IE 8 standards mode, then use this metatag along with a valid DOCTYPE:

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

Note the "EmulateIE8" value rather than the plain "IE8".

According to IE devs, this should, "Display Standards DOCTYPEs in IE8 Standards mode; Display Quirks DOCTYPEs in Quirks mode. Use this tag to override compatibility view on client machines and force Standards to IE8 Standards."

more info on this IE blog post: http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx

春夜浅 2024-09-02 09:15:15

此问题与 Force "Internet Explorer 8" browser mode in Intranet 重复

那里的响应表明不可能禁用兼容性视图(在服务器端) - https://stackoverflow.com/a/ 4130343/24267。情况似乎确实如此,因为我尝试过的建议都没有奏效。在 IE8 中,无论您发送何种类型的 X-UA-Compatible 标头,“浏览器模式”都会设置为 Internet Explorer 8 兼容性视图。

我必须对 IE7 和兼容模式进行一些特殊处理,这导致浏览器使用 IE8 进行渲染,但报告它是 IE7,破坏了我的代码。
这就是我修复代码的方法(我知道这是一个可怕的黑客攻击,我应该测试功能而不是浏览器版本):

isIE8 = navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 8;
if (!isIE8 && navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 7 && navigator.appVersion.indexOf("Trident") != -1) {
    // Liar, this is IE8 in compatibility mode.
    isIE8 = true;
}

This question is a duplicate of Force "Internet Explorer 8" browser mode in intranet.

The responses there indicate that it's not possible to disable the compatibility view (on the server side) - https://stackoverflow.com/a/4130343/24267. That certainly seems to be the case, as none of the suggestions I've tried have worked. In IE8 the "Browser Mode" gets set to Internet Explorer 8 Compatibility view no matter what kind of X-UA-Compatible header you send.

I had to do some special handling for IE7 and compatibility mode, which caused the browser to render using IE8 but report it was IE7, broke my code.
This is how I fixed my code (I am aware this is a horrible hack and I should be testing for features not browser versions):

isIE8 = navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 8;
if (!isIE8 && navigator.appVersion.indexOf("MSIE") != -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) == 7 && navigator.appVersion.indexOf("Trident") != -1) {
    // Liar, this is IE8 in compatibility mode.
    isIE8 = true;
}
野鹿林 2024-09-02 09:15:15

有同样的问题。它通过使用起作用

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

Had the same problem. It worked by using

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
长伴 2024-09-02 09:15:15

将其添加到您的页面头标记中(针对您想要的 IE 版本):

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

注意,这不会改变浏览器处于兼容模式(称为浏览器模式)的事实,但页面 <将会以 IE8 标准模式呈现。如果它仍然没有按照您希望的方式呈现,可能是因为您的 javascript 错误地检查了 IE 版本。请参阅下面的博客文章来确定您应该关闭哪个属性,因为即使您设置了元 X-UA-Compatible 标记,用户代理字符串也会还是说MSIE 7.0。

就我而言,为了修复此问题,我必须添加对 IE7 兼容性模式的检查。我使用简单的 JavaScript 代码做到了这一点:

                //IE8 and later will have the word 'trident' in its user agent string.
                if (navigator.userAgent.indexOf("Trident")>-1) { //do something }

Add this inside your pages head tag (targeting the IE version you want):

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

Note, this will NOT change the fact that the browser says its in compatibility mode (called the browser mode), but the page will render in IE8 standards mode. If its STILL not rendering how you wish, its probably because you have javascript that is erroneously checking the I.E. version. See the following blog post to determine which property you should be keying off of because even if you set the meta X-UA-Compatible tag, the user agent string will still say MSIE 7.0.

In my case, for the fix I had to add a check for IE7 Compatibility mode. I did so using a simple javascript code:

                //IE8 and later will have the word 'trident' in its user agent string.
                if (navigator.userAgent.indexOf("Trident")>-1) { //do something }
杀お生予夺 2024-09-02 09:15:15

对于阅读本文的其他人希望通过 GPO 为所有用户禁用此功能,请执行以下设置:

计算机配置/管理模板/Windows 组件/Internet Explorer/兼容性视图/打开本地 Intranet 的 Internet Explorer 标准模式,

尽管 web.config 编辑为我修好了。

For anyone else reading this looking to disable this via GPO for all users, this is the setting:

Computer Configuration/Administrative Templates/Windows Components/Internet Explorer/Compatibility View/Turn on Internet Explorer Standards Mode for Local Intranet

although the web.config edit fixed it for me.

漫雪独思 2024-09-02 09:15:15

更改 .htaccess 中的标头

BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie

在这里找到了此问题的解决方案: https://github.com /h5bp/html5-boilerplate/issues/378

Change the headers in .htaccess

BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie

Found the solution to this problem here: https://github.com/h5bp/html5-boilerplate/issues/378

撑一把青伞 2024-09-02 09:15:15

Stefan S 关于文档模式与浏览器模式的评论与我的问题非常相关。

我在页面中有 X-UA-Content 元数据,但我是通过 navigator.appVersion 在客户端测试浏览器版本。该测试不反映元数据,因为它提供的是浏览器模式而不是文档模式。

我的答案是测试 document.documentMode ,例如:

function IsIE(n)
{
    if (navigator.appVersion.indexOf("MSIE ") == -1) return false;
    var sDocMode = document.documentMode;
    return (isFinite(sDocMode) && sDocMode==n);
}

现在,我的元 X-UA-Content 标记反映在我的浏览器测试中。

为什么我要做测试浏览器这样令人不悦的事情?速度。我的各种 jQuery 插件(例如 tablesorter)在 IE6/7 上太慢了,我想将它们关闭。我不确定测试浏览器功能是否可以帮助我解决这个问题。

Stefan S' comment about the document mode versus browser mode were very pertinent for my problem.

I have the X-UA-Content meta data in the page, but I was client-side testing the browser version via navigator.appVersion. This test does not reflect the meta data because it is giving the browser mode not the document mode.

The answer for me was to test the document.documentMode something like:

function IsIE(n)
{
    if (navigator.appVersion.indexOf("MSIE ") == -1) return false;
    var sDocMode = document.documentMode;
    return (isFinite(sDocMode) && sDocMode==n);
}

Now, my meta X-UA-Content tag reflects in my browser test.

Why do I do such a frowned-on thing as test the browser? Speed. Various of my jQuery add-ins, like tablesorter are just too slow on IE6/7, and I want to turn them off. I am not sure that testing for browser features can help me solve this otherwise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文