Skip navigation.

Claws, fangs, fur...

...the bear essentials

Google Maps Sucks

, , , ,

For community websites I’m building a member locator using Google Maps to allow members to locate themselves and others around them. Pretty neat.

What isn’t neat is the following: the Google example code shows to use an XHTML doctype. Yay! Erm, no. See, in order for Microsoft’s excuse for a web browser to understand XHTML, it has to treat it as HTML, rendering all the advantages of using XHTML completely useless. The server admins know that, and instead of sending XHTML as XHTML, they send it as HTML. So the document claims to be XHTML, while both the server and the browser assume it to be HTML.

Big difference? Big difference!

Why?

Because XHTML is much, much more strict than HTML, and much, much more extensible. It’s a web author’s godsend, and a browser’s nightmare at the same time.

As said, Google Maps examples show that authors should be using XHTML files. Since I’m testing my scripts in decent browsers (Firefox, Opera), I assumed that it would be no problem to have my server send them as XHTML. Yes, I had to be the wise guy who actually tried to adhere to the standards as recommended. Took me 4 hours to recognise Google’s mistake, and 2 seconds to correct it.

The symptom: my browser wouldn’t load some of Google’s scripts, indicated by its complaining that my code was calling objects that didn’t exist.

The problem: Google’s Map scripts use a function that overwrites the running application with new code. (For insiders: check out the GScript function.)

Why is this a problem? Because the running application is being erased and overwritten by itself. XHTML is protected from such malpractice. Thus Google’s code won’t work.

HTML, as said, is far less strict. HTML browsers assume that the new code is going to be appended to the existing application, instead of overwriting it. So HTML browsers are mis-executing code which then results in a desired behaviour, while XHTML browsers are correctly exucting the same code, which then results in undesired behaviour… nice catch-22.

Google Maps documentation doesn’t talk about this catch. They probably assume everyone sends their XHTML documents as HTML, just like Microsoft. Their examples are 2 years old, and I’ve seen complaints about this same topic as far back as 18 months.

By advocating mis-use and malpractice, Google promotes the confusion about web standards, and suports Microsoft’s wish to dominate the web. I wonder whether Google has stock in Microsoft.

I haven’t found a strict XHTML solution yet, but if I did, it wouldn’t work in Microsoft’s poor excuse of a browser anyway.

Data URIs and MSIExhtml and in-page scripts / styles

Comments

Sathallrin 27. August 2007, 19:37

You say "and 2 seconds to correct it."

Do you have a real fix to the problem, or was this simply reverting to "text/html"?

Omega Junior 28. August 2007, 09:33

Yes, reverting to text/html was the correction.

Seeing how I have yet been unable to persuade Microsoft to have their flagship browser accept application/xhtml+xml, nor have been able to persuade Google to correct their examples into using an HTML doctype, this is all that was left.

For now. :wink:

Omega Junior 5. September 2007, 07:21

I found a workaround.

The document.createElement() function (javascript, DOM 1) can create a script element. (Of course, once created and identified, we can reuse the same script element over and over again.) Using element.setAttribute() we can assign a script source. Then we append the new script to the document and we're set.

I should tell Google, but I think they know about this and simply refuse to do it. They prolly want to care about backwards compatibility. I don't care about backwards browsers... not much, anyway. :wink:

Here's the code, which I succesfully applied in a different page on my site, including a call-back inside the external script... resulting in a complete and utter annihilation of AJAX-need. :D


if ((document)&&(document.createElement)) {
var theNewScript = document.createElement('script');
if ((theNewScript)&&(theNewScript.setAttribute)) {
theNewScript.setAttribute('id','myNewScript');
theNewScript.setAttribute('type','text/javascript');
theNewScript.setAttribute('src','http://domain/dir/script.js');
}
if (document.body.appendChild) {
document.body.appendChild(theNewScript);
} else if (document.documentElement.appendChild) {
document.documentElement.appendChild(theNewScript);
} else if (document.appendChild) {
document.appendChild(theNewScript);
}
}


Happy coding!

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

Download Opera, the fastest and most secure browser