繁体   English   中英

正确放置带有http-equiv属性的META标签?

[英]Proper placement of META tags with http-equiv attribute?

我正在页面上实现Bing Maps(我希望使用Google Maps,但这不是我的选择)。 我正在关注MS在此处提供的教程: http : //msdn.microsoft.com/zh-cn/library/bb412551.aspx

使用MS的代码,一切正常。 用一些我自己的jQuery代码充实它,我发现每当我运行$ .get()时,都会遇到“ Permission Denied”错误。 我以为这是某种“相同起源”冲突,但是经过大量检查,我确定我没有从任何其他主机请求任何东西(甚至连www.example.com与example.com都没有-一切都在SAME上)主办)。

经过无奈的尝试,我最终将原因归结为MS代码中的META标签:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

这是在我的HEAD部分的底部。 在阅读规格。 对于META标记(我不太熟悉),我发现有些服务器可以将http-equiv标记直接转换为HTTP标头,而其他服务器则可以按原样发送它们。 由于我认为必须在发送任何内容之前发送标头,因此我将META标记移至HEAD节的BEGINING处,一切正常。

另一个细节:我只在IE7中遇到问题。 当我在FF中测试时,我一点都没有问题。

所以这是我的问题:具有http-equiv属性的META标签是否应位于HEAD部分的开头? IE只是很奇怪吗? 还是FF只是特别宽容?

谢谢!

从HTML5规范草案( http://dev.w3.org/html5/spec/semantics.html#charset ):

4.2.5元元素

[片段]

4.2.5.5指定文档的字符编码

状态:上次征求意见

字符编码声明是一种机制,通过该机制可以指定用于存储或传输文档的字符编码。

以下限制适用于字符编码声明:

 * The character encoding name given must be the name of the character encoding used to serialize the file. * The value must be a valid character encoding name, and must be an ASCII case-insensitive match for the preferred MIME name for that encoding. [IANACHARSET] * The character encoding declaration must be serialized without the use of character references or character escapes of any kind. * The element containing the character encoding declaration must be serialized completely within the first 512 bytes of the document. * There can only be one character encoding declaration in the document. 

请注意第四个要点。 我认为512字节规则是传统浏览器之间的折衷,这些浏览器过去选择了不同的限制,但我认为所有这些浏览器的字节限制都具有一定的长度。 这可能就是原因,尽管它为什么会导致“权限被拒绝”错误,但我不知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM