/    Sign up×
Community /Pin to ProfileBookmark

Validating the google javascript – To felgall

Felgall,

I’m not allowed in over at the JavaScript forum but from time to time I take a peek. Your answer to [url]http://www.webdeveloper.com/forum/showthread.php?p=979498#post979498[/url] omitted a couple of points.

The long and short of it is that there is no way to make the Google analytics JavaScript XHTML compliant and it’s invalid for HTML as well.

In XHTML you don’t [i]have[/i] to mark up your scripts as CDATA…as long as they don’t contain any ampersands or less than characters. And don’t try the old HTML trick of commenting out the script, in XML the browser is allowed to completely ignore comments. But that script does contain both of those troublesome characters so you would think that you have to escape or move it to an external file. But upon closer inspection we find that the code uses the dread method “document.write”, something that is not supposed to work in XHTML.

Now, “document.write” will work in XHTML if the browser is treating it as HTML. But not that script. In HTML the SCRIPT and STYLE elements are defined a special cases of CDATA, so you don’t need the CDATA marks. And so the browser knows when to resume parsing as HTML, and what makes this CDATA special, the end is marked by the “ETAGO (‘</’) delimiters followed immediately by a name character [a-zA-Z]”. ( [url]http://www.w3.org/TR/REC-html32#script[/url] ) Again, close inspection finds the ETAGO in that piece of script.

If you want to use that you’ll have to switch to HTML, no great loss, [i]and[/i] you’ll have to move it to an external file.

to post a comment
HTML

0Be the first to comment 😎

×

Success!

Help @Charles spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...