指定在iframe中加载的页面的字符集 [英] specify charset of page loaded in iframe
问题描述
我想知道,是否可以为加载的iframe提供自定义字符集?
例如,如果我有一个名为 www.example.com
的源代码的页面:
I was wondering, is it possible to supply a custom charset for a loaded iframe?
E.g if i have a page named www.example.com
with source code:
<meta charset=utf-7>
<html>
<body>
Test
</body>
</html>
现在我有一个名为 www.example2.com
,我想要做的是在 iframe
中加载 www.example.com
并设置字符集加载的 iframe
页面到 utf-8
,这可能吗?如果是的话如何?
Thanks。
Now i have a site named, www.example2.com
, what i want to do is load www.example.com
in an iframe
and set the charset of the loaded iframe
page to utf-8
, is this possible? if so how?
Thanks.
推荐答案
顺便说一句,您的示例代码不正确。字符集应该像这样声明(假设HTML 5):
By the way, your sample code is incorrect. The charset should be declared like this (assuming HTML 5):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-7">
</head>
<body>
Test
</body>
</html>
或者,您可以通过HTTP标头声明charset,如下所示:
Alternatively, you can declare the charset via a HTTP header like this:
Content-Type: text/html; charset=utf-7
在 http://www.w3.org/International/O-HTTP-charset
通常很难将Web服务器配置为为每个单独文件输出正确的标题,这就是为什么 meta
标记更常见的原因。
It's usually harder to configure the web server to output the correct header for each individual file which is why the meta
tag is more common.
这篇关于指定在iframe中加载的页面的字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!