views:

19

answers:

1

I'm implementing Bing Maps on a page (I'd prefer Google Maps, but it's not my choice). I'm following the tutorial MS provides here: http://msdn.microsoft.com/en-us/library/bb412551.aspx

Using MS's code, everything worked just fine. Fleshing it out with some of my own jQuery code, I found that I was getting a "Permission Denied" error every time I ran $.get(); I assumed this was some sort of "Same Origin" conflict, but after much checking, I determined that I wasn't requesting anything from any other host (not even www.example.com vs. example.com - everything was on the SAME host).

After much frustration, I finally whittled the cause down to the META tag in MS's code:

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

This was towards the bottom of my HEAD section. In reading the spec. for the META tag (which I wasn't very familiar with), I found that some servers may translate http-equiv tags directly into HTTP headers, while others may just send them as-is. Since I believe headers must be sent before any content, I moved the META tag to the BEGINING of the HEAD section, and everything worked fine.

Another detail: I only had problems in IE7. When I tested in FF, I had no problems at all.

So here's my question: Are META tags with the http-equiv attribute SUPPOSED to be at the begining of the HEAD section? Was IE just being weird? Or was FF just being particularly forgiving?

Thanks!

+1  A: 

From the HTML5 draft spec (http://dev.w3.org/html5/spec/semantics.html#charset):

4.2.5 The meta element

[snip]

4.2.5.5 Specifying the document's character encoding

Status: Last call for comments

A character encoding declaration is a mechanism by which the character encoding used to store or transmit a document is specified.

The following restrictions apply to character encoding declarations:

* 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.

Note the fourth bullet point. I believe that the 512 byte rule was a compromise between the legacy browsers which have in the past chosen different limits, but all, I think, had a byte limit of some length. This may be the reason, though why it should cause a "Permission Denied" error, I've no idea.

Alohci
Thanks for the answer! In some cases, the page was being referred (through HTTP forward header) from another page, and I'm wondering if it was somehow screwing with the headers, which could conceivably (to me at least) mess with the same-origin policy.Thanks again!
loneboat