I've come across a bug/undocumented feature in IE 7, 6.5 (perhaps others?). This doesn't effect Opera (10.5x) Firefox (3.5.x) or likely any other browser (this is all I've tested so far). It doesn't seem to be a documented ability of Javascript.
By including a comment denoted by double slashes, and directly followed by double at signs (//@@
), the whole .js
file is rendered useless. I've checked several variations and here's what I've found (where fail=JS isn't loaded, pass=JS is loaded):
//@@
//@ @
//@@@
- any number of @ doesn't seem to make a difference//@@ text
- any content following doesn't seem to help//@hello@
- any content between @ doesn't seem to help// @@
// @ @
- space before first @ seems to prevent//hello @@
- any content before first @ seems to prevent/*@@*/
- only seems to apply to //
comment styleIE 7 - just ignores the file, when trying to reference the content of that file you get an error along the lines of "<function/object> is undefined
". IE6.5 has the decency to report "Invalid character
" which significantly improves your ability to find the problem!
And so the question: Does anyone know why this is happening and what's going on?
You can work with it (insert a space, use the other comment style etc) but it's worth noting the problem's there, since can be time-consuming to debug.
UPDATE: How to reproduce:
Source: flaw.ie.html
<html lang="en">
<head>
<title>Test</title>
<script src="turnon.cc.js"></script>
<script src="flaw.ie.js"></script>
</head>
<body>
World
</body>
</html>
Source: flaw.ie.js
//@@
alert('hello');
Source: turnon.cc.js
/*@cc_on
@*/
Result:
IE: page:World
FF/Opera: Alert:Hello! page:World
Potential conclusion: Once conditional compilation is turned on in IE, be careful with comments that vaguely resemble the syntax.
Most likely related to conditional comments:
http://www.javascriptkit.com/javatutors/conditionalcompile.shtml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With