.:∴ Archives ∴:.
Tierra Verde

Saturday, July 31

Now I understand about HTML comments and JS - Delimiter: July 2004 Archives  


From Delimiter: July 2004 Archives:
The Strange Zen Of JavaScript #3: script-killer comments

This one seems like a no-brainer, but it had several of our best JS experts stumped for a good while, until we saw what was right in front of us all along.

A script for preloading images was failing. The source was similar to this (imagine 20 or more lines of unbroken script):

<script type='text/javascript'>
<!-- preload_images ('header1.gif', 'header2.gif', 'logo.gif');
//-->
</script>

Notice how the first line of script is preceded by an HTML comment delimiter. This prevented the preload_images function from running, as the JS interpreter just skipped over the entire line. For the want of a linebreak, the script was hosed.

This seems to be common when JS is generated from some backend process. The above JavaScript was generated from a server-side application written in C .
This explains why, when I was trying to make my blog pages valid, putting the one-liner javascript code in HTML comments didn't work. Well, it made the error go away, but the code never executed. :-P

Interesting...

Relevant Link

Permanent link posted by bytehead @ 7/31/2004 10:59:00 AM   Edit this entry 0 comments Links to this post

0 Comments:

Post a Comment

Links to this post:

Create a Link

 

Article Index

Now I understand about HTML comments and JS - Delimiter: July 2004 Archives
Copyright © 2003-2008, Bryan Price. Licensed by Creative Commons License: Creative Commons License
Home| This page| Colophon| Disclaimer| Privacy Statement