我正在尝试追踪一个错误:https://github.com/OscarGodson/EpicEditor/issues/184#issuecomment-8805982
根据所有信息,似乎是因为浏览器默认使用用户的本地字符集(在这种情况下为ISO-8859-1),而不是像在我的机器和其他美国人的机器上一样使用UTF-8。我猜解决方法是使用HTML强制编码为UTF-8:
<meta charset='utf-8'>
或者<meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>
但是,JS没有起作用。在第一个例子中:
charsetMetaTag = self.editorIframeDocument.createElement('meta');
charsetMetaTag.charset = 'utf-8';
self.editorIframeDocument.getElementsByTagName('head')[0].appendChild(charsetMetaTag);
我刚刚从DOM中获取了以下注入的内容:
<meta>
在第二个示例中,http-equiv
没有被设置:
charsetMetaTag = self.editorIframeDocument.createElement('meta');
charsetMetaTag['http-equiv'] = 'Content-Type';
charsetMetaTag['content'] = 'text/html; charset=utf-8';
self.editorIframeDocument.getElementsByTagName('head')[0].appendChild(charsetMetaTag);
我得到了以下的HTML:
<meta content="text/html; charset=utf-8">
是的,我需要动态地完成这个操作,因为我正在动态创建 iframes。这可能甚至不是问题,但看起来是这样。 我唯一想到的“hack”方法是以某种方式使用 innerHTML...