Osc*_*son 13 html javascript utf-8 character-encoding epiceditor
我试图在这里找到一个错误: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">
是的,我需要动态地动态创建iframe.这可能不是问题,但这就是它的样子.我能想到的唯一"黑客"是以某种方式使用innerHTML ......
Alo*_*hci 19
您不能通过设置charset属性来设置charset内容属性,因为它们不会相互反映.实际上,没有反映charset内容属性的属性.
http-equiv内容属性由httpEquiv属性反映出来
 charsetMetaTag['httpEquiv'] = 'Content-Type';
会正确地创建元素.
但这一切都不重要.字符集由解析器建立,因此在解析HTML之后在JavaScript中构造元元素根本不会影响文档的字符集.
| 归档时间: | 
 | 
| 查看次数: | 10764 次 | 
| 最近记录: |