设置IE8的文档模式

时间:2014-05-30 12:43:55

标签: internet-explorer internet-explorer-8 ie8-compatibility-mode

我创建了一个Web应用程序,它在firefox和chrome中运行良好,但在IE8中没有。

我尝试在标题中使用以下代码来设置文档模式:

                             

<head>
<!-- meta tags -->
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
<meta name="author" content="Web">
<meta name="description" content="Medical Services">
<meta name="robots" content="index, follow">
<!-- mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="viewport" content="minimal-ui">
</head>

我试过这段代码,但这不起作用。如果我使用开发人员工具在IE中手动选择文档模式“IE8 Standards”,那么它的工作正常。但我想将“IE8标准”设置为默认文档模式。 我怎样才能做到这一点?请帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

当您的本地主机或本地网络上的其他计算机上运行网站时,X-UA-Compatible标记将无法正常工作。此外,代码在代码中显示两次,只应列出一次。

删除其中一个代码,如果它仍然没有按预期工作,则需要在服务器上设置此代码。

如果您的网站运行ASP.NET,请将其放在您的web.config中:

<configuration>
   <system.webServer>
      <httpProtocol>
         <customHeaders>
            <clear />
            <add name="X-UA-Compatible" value="IE=EmulateIE8" /> <!-- or other value of your choice -->
         </customHeaders>
      </httpProtocol>
   </system.webServer>
</configuration>

如果您的网站运行PHP,请将其放在页面的第一行:

<?php
header('X-UA-Compatible: IE=EmulateIE8');
?>
<!-- or other value of your choice -->

或者如果您的站点在Apache中运行,请将其设置在.htaccess文件中以全局启用它:

<IfModule mod_headers.c>
  Header set X-UA-Compatible "IE=Edge,chrome=1"
  # Don't send it for non-HTML content
  <FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
    Header unset X-UA-Compatible
  </FilesMatch>
</IfModule>