isn't quite ashamed enough to present

jr conlin's ink stained banana

:: I Hate IE (and Opera's Been Warned)

Ok, here's one to put on your "Oh Dear Lord That's Retarded" list:

The following code produces no errors but fails to run either.
<b>this displays</b>
<script type='text/javascript'>
/* detect a comment */
if (document.getElementById('field').value.match(/<!--/))
alert('You entered a Comment');
</script>
More stuff that displays

Ok, that's greatly simplified, but for IE and Opera the above produces no Javascript errors or warnings, it simply doesn't work. Using the various consoles only states that there's no code there and that you should only set breakpoints where there's code.

This works peachy keen in Firefox.

Several freshly plucked forehead impressions into a desk later you'll figure out that '<!–' is interpreted by IE and Opera before <script> is and that it will happily consider all the content of that script tag invalid with no warning or error. Isn't that nice?

The solution is to break the "comment" sequence which appears inside of a string in a script tag sequence so that the HTML parser doesn't get "confused".

e.g.
var comment = '< '+'!--';

i'll add that you also have to do the same inane handling if you have "<sc"+"ript>" as a string because that am smart!

*grumble*

Blogs of note
personal that's my blog
(The Official Blog of the Internet)
memoirs of hydrogen guy matthew shepherd (quebec) rhapsodic.org Henriette's Herbal Blog lynne ydw i slumbering lungfish
geek jeremy z
(The Official Website of the Internet)
dave's picks ultramookie Josh Woodward derek balling
news ars technica search engine watch

Powered by WordPress
Hosted on Dreamhost.