Internet Explorer 9将无法识别servlet从weblogic服务器发送的doctype,并以IE7的文档模式呈现-启动前是否有多余的字符? [英] Internet explorer 9 will not recognize doctype sent by servlet from weblogic server and renders in document mode IE7 - extra characters before start?

查看:80
本文介绍了Internet Explorer 9将无法识别servlet从weblogic服务器发送的doctype,并以IE7的文档模式呈现-启动前是否有多余的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

当我在本地或服务器上放置页面时,Internet Explorer 9不会以相同的方式考虑<!DOCTYPE html>.我做了一个简单的测试页来突出问题:

Internet Explorer 9 does not take the <!DOCTYPE html> into account in the same way when I have my page locally or on my server. I made a simple test page to highlight the problem:

编辑:使用元标记和CSS链接更新了简单的测试页面

updated simple test page with meta tag and css link

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="css/environmentinfo.css" />
        <meta http-equiv="x-ua-compatible" content="IE=edge"/>
    </head>
    <body>
        <script>
            document.write(document.compatMode);
            document.write('<br/>');
            document.write(document.documentMode);
        </script>
    </body>
</html>

当我在IE9中的本地系统上打开文件时,它显示:

When I open the file on my local system in IE9 it shows:

CSS1Compat

CSS1Compat

9

当我将其部署到服务器上时,它显示:

When I deploy it on the server it shows:

CSS1Compat

CSS1Compat

7

服务器

因此,我正在从Weblogic服务器提供文件.它部署在一个简单的war归档文件中,并由默认servlet提供服务. 本地文件仅由文件系统提供服务(网址栏中的C:... \ test.html).

So I'm serving the file from a weblogic server. It is deployed in a simple war archive and it is served by the default servlet. The local file is just served by the filesystem (C:...\test.html in the url bar).

调试信息

我研究过编码(两者相同)和有效字符(通过notepad ++和通过wirehark).

I've looked at encoding (both the same) and the effective characters present (via notepad++ and via wireshark).

本地文件:

<!DOCTYPE html>\r\n
<html lang="en">\r\n
    <head>\r\n
    </head>\r\n
    <body>\r\n
        <script>\r\n
            document.write(document.compatMode);\r\n
            document.write('<br/>');\r\n
            document.write(document.documentMode);\r\n
        </script>\r\n
    </body>\r\n
</html>

服务器响应:

HTTP/1.1 200 OK\r\n
Date: Fri, 13 Mar 2015 12:34:26 GTM\r\n
Accept-Ranges: bytes\r\n
Content-Length: 427\r\n
Content-Type: text/html\r\n
Last-Modified: Fri, 13 Mar 2015 12:29:30 GMT\r\n
X-Powered-By: Servlet/3.0 JSP/2.2\r\n
\r\n
<!DOCTYPE html>\r\n
<html lang="en">\r\n
    <head>\r\n
    </head>\r\n
    <body>\r\n
        <script>\r\n
            document.write(document.compatMode);\r\n
            document.write('<br/>');\r\n
            document.write(document.documentMode);\r\n
        </script>\r\n
    </body>\r\n
</html>

我看过其他一些类似的问题,并且发现IE如果前面有任何字符,它将忽略<!DOCTYPE html>.我检查了html规范,并指出了标头,然后是换行符,然后是文档的开头.因此,似乎没有多余的字符.使用wireshark,我可以看到实际的字节,而且似乎没有任何多余的字符.答案,技巧甚至其他值得一看的东西都将不胜感激.

I've looked at some other similar questions and I've found that IE will ignore the <!DOCTYPE html> if there are any characters before it. I checked the html spec and it states headers, then a newline and then the start of the document. So it seems there are no extra characters. With wireshark, I could see the actual bytes and there don't seem to be any extra characters. Answers, tips and even other things to look at would all be appreciated.

推荐答案

IE可能有一些配置设置会覆盖标记中的<!doctype html>.按照 https://msdn.microsoft. com/zh-CN/library/ie/jj676914(v = vs.85).aspx :

IE may have some configuration settings that override <!doctype html> in the markup. As per https://msdn.microsoft.com/en-us/library/ie/jj676914(v=vs.85).aspx:

根据浏览器的配置,组策略选项的存在以及其他因素,在Intranet区域中打开的页面可能会有所不同.

Pages opened in the Intranet zone might be treated differently, depending on the configuration of the browser, the presence of group policy options, and other factors.

尝试检查上面文章中列出的地点.

Try to check places listed in the article above.

除此之外,您可以按照X-UA-CompatibleHTTP标头或<meta>标记强制使用文档兼容模式/ie/jj676913(v=vs.85).aspx"rel =" nofollow> https://msdn.microsoft.com/zh-CN/library/ie/jj676913(v = vs.85).aspx

In addition to that, you can try to force document compatibility mode using either X-UA-Compatible HTTP header or <meta> tag as per https://msdn.microsoft.com/en-us/library/ie/jj676913(v=vs.85).aspx

在某些讨厌的情况下,如果将标准兼容页面加载到由怪癖页面托管的iframe中,则可能需要重新加载该iframe才能将其强制为正确的文档模式.

In some nasty cases when a standards compliant page is loaded inside an iframe hosted by a quirks page it may be required to reload the iframe to force it to the right document mode.

请注意,一旦IE开始呈现页面,文档模式将最终确定,并且无法即时更改.因此,关于文档模式的每条指令都必须尽早出现.例如,正如您已经提到的,<!doctype html>必须是第一行,带有X-UA-Compatible<meta>必须是<head>中的第一行标签.我想说的是,如果您可以控制服务器端,请使用HTTP标头而不是<meta>来确保它在进行任何渲染之前切换文档模式.

Please note that once IE starts rendering the page the document mode is finalized and can't be changed on the fly. Thus, every instruction on the document mode has to appear as early as it can. For example, as you already mentioned, <!doctype html> has to be the very 1st line, <meta> with X-UA-Compatible has to be the very 1st tag in the <head>. I'd say if you have control over the server side use HTTP header instead of <meta> to make sure it switches document mode before any rendering happens.

这篇关于Internet Explorer 9将无法识别servlet从weblogic服务器发送的doctype,并以IE7的文档模式呈现-启动前是否有多余的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆