2

我面临一个奇怪的问题。html 中的文本有重音符号,例如:

<p>é</p>

它在屏幕中正确显示 (é),但 DOM 实例中的内容不接受重音符号。它显示一个“?” 字符而不是带重音的字符。

就我而言,我正在使用 chrome 扩展程序在 Kindle ( http://read.amazon.com ) 中注入 javascript 代码,但我认为这并不重要,因为我只使用 chrome 控制台就可以看到问题。

html结构的简化版本:

<html>
    <head>
        ...
        <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
        ...
    </head>
    <body>
        ...
        <iframe id="KindleReaderIFrame">
            <html>
                <head>
                    ...
                    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
                    ...
                </head>
                <body>
                    ...
                    <iframe id="column_0_frame_0">
                        <html>
                            <head>
                                <!-- Do not have the Content-Type meta tag -->
                            </head>
                            <body>
                                <!-- Text with accents that I intend to get through DOM -->
                            </bady>
                        </html>
                    </iframe>
                    ...
                </body>
            </html>
        </iframe>
        ...
    </body>
</html>

我想要的文本在“column_0_frame_0”iframe 内。

4

1 回答 1

0

Going through your code, you have not closed the body tag correctly, see below :

<iframe id="column_0_frame_0">
    <html>
       <head>
        <!-- Do not have the Content-Type meta tag -->
        </head>
        <body>
            <!-- Text with accents that I intend to get through DOM ->
        </bady>
    </html>
</iframe>

Secondly, if you are loading your contents in iFrame or through AJAX, its not enough to set the character set in meta tag, sometimes it depends on the IDE which you used to create your code.

To check:

  1. Open the same code in Notepad++
  2. Save the contents using charset UTF-8 (default ANSI).
  3. Run code on your local server without opening the file in any other IDE.

Now you will be able to render the accents correctly in DOM as well as screen.

于 2013-07-08T12:13:45.067 回答