为什么 IE 无法显示 UTF-8 编码的文本? [英] Why is IE failing to show UTF-8 encoded text?

查看:22
本文介绍了为什么 IE 无法显示 UTF-8 编码的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在由 Kentico 支持的网站上显示一些中文字符.此文本被复制/粘贴到 Kenticos FCK 编辑器中,然后保存并显示在站点上.在 Firefox、Chrome 和 Safari 中,字符显示完全符合预期.在 IE 8 标准模式下,我只能看到框.

文本是 UTF-8 编码的,据我所知,它在服务器的响应中被正确编码.有一个 Content-Type: text/html;charset=utf-8 响应头,以及一个 <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> meta页面上的标签.当我从服务器下载 HTML 并将相关字符的字节与原始 UTF-8 文本文档进行比较时,字节全部匹配,除了 HTML 不包含 BOM.

这似乎是标准模式下的 IE 8 特有的.在 IE 8 Quriks 中:它有效.IE 7 标准:有效.IE 7 怪癖:有效.我不确定标准模式会如何导致这个问题.

奇怪的是,如果我从 IE 查看源代码,字符会正确显示在源代码视图中.

对这里可能出现的问题有什么建议吗?我是否遗漏了一些明显的东西?

解决方案

我无法详细解释.但这确实是一个已知问题.

这是一个可重现的小代码片段:

<html lang="zh-cn"><head><title>test</title></head><body><p>&#65185;<br>0 0</p></body>

以UTF-8格式保存并在IE8中查看.你什么也看不见.将 0 0 替换为 00 并重新加载页面.它会工作得很好!这绝对是惊人的.奇怪的是,将 0 0 替换为 aa 或将
替换为

代码> 也会修复它.这与空白渲染失败有关.

抱歉,我没有权威资源证明这一点,但这只是 IE8 没有我们预期的那么好的另一个证据.最好的办法是尝试更改 HTML 和/或逐步构建它,使其在某些时候起作用或无效时,将以下元标记添加到头部以强制 IE8 进入 IE7 模式:

I have a some Chinese characters that I'm trying to display on a Kentico-powered website. This text is copy/pasted into Kenticos FCK editor, and is then saved and appears on the site. In Firefox, Chrome, and Safari, the characters appear exactly as expected. In IE 8 Standards mode, I see only boxes.

The text is UTF-8 encoded, and as far as I can tell, it is encoded correctly in the response from the server. There is a Content-Type: text/html; charset=utf-8 response header, and a <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> meta tag on the page too. When I download the HTML from the server and compare the bytes of the characters in question to the original UTF-8 text document, the bytes all match, except the HTML does not include a BOM.

This seems to be specific to IE 8 in Standards mode. In IE 8 Quriks: it works. IE 7 Standards: it works. IE 7 Quirks: Works. I'm not sure how standards mode would cause this problem.

Strangely, if I view-source from IE, the characters show up in the source view correctly.

Any suggestions on what might be wrong here? Am I missing something obvious?

解决方案

I can't explain this in detail. But this is indeed a known problem.

Here's a small reproducible code snippet:

<!DOCTYPE html>
<html lang="en">
    <head><title>test</title></head>
    <body><p>&#65185;<br>0 0</p></body>
</html>

Save it in UTF-8 and view in IE8. You see nothing. Replace 0 0 by 00 and reload the page. It'll work fine! This is absolutely astonishing. Weirdly, replacing 0 0 by a a or the <br> by a </p><p> will fix it as well. It'll have something to do with failures in whitespace rendering.

Sorry, I don't have authorative resources proving this, but this is just another evidence IE8 isn't as good as we expect it is. Your best bet is to try to change the HTML and/or build it step by step so that it works at some point or when in vain, add the following meta tag to the head to force IE8 into IE7 mode:

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

这篇关于为什么 IE 无法显示 UTF-8 编码的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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