...

View Full Version : HTML-like Comment Tags in JavaScript???



jeff00seattle
12-12-2010, 12:13 AM
I came across some embedded JavaScript code and I noticed some weird “HTML comment-like tags” within embedded JavaScript that are getting rendered in FireFox but not IE. Specifically the closing tag "//-->"

And the JavaScript code between these tags is functional (not commented out)!


<SCRIPT type=text/javascript>
<!--

....

//-->
</SCRIPT>

What are these?

Example usage:


<SCRIPT type=text/javascript>
<!--
var zz, zv, d, fTSR;
d = new Date();
fTSR=0;
zv = d.getTime();
zz = "&zz="+zv;

var gBF=false;
function GoTo(u){window.top.location = u + zz;}
function Go(u){window.top.location = u;}

....

//-->
</SCRIPT>

jmrker
12-12-2010, 12:15 AM
Deprecated tags to hide scripts from browsers that cannot handle them.
Remove them and all should be well

Comments in JS are either
// one line comment
/*
Multi-line
comments
*/

jeff00seattle
12-12-2010, 12:19 AM
Deprecated tags to hide scripts from browsers that cannot handle them.


How long have they been "deprecated"?

jmrker
12-12-2010, 02:14 AM
How long have they been "deprecated"?

Don't remember ... don't care.

See: http://www.w3schools.com/js/js_howto.asp
section about "How to handle simple browsers".
Both FF and MSIE should ignore them, but if they are giving you problems, remove them because they are not needed in NEW browsers.

If you are trying to execute a XHTML instead of a HTML document
see http://www.w3schools.com/tags/tag_script.asp for a discussion of the differences.

Among other statements, in http://javascript.crockford.com/script.html it states


Do not use the <!-- //--> hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years. <!-- //--> is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include --, so a script that decrements has an HTML error.
language="javascript"

This attribute has been deprecated. It was used to select other programming languages and specific versions of JavaScript. You don't need it. Don't use it.
type="text/javascript"

This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.

Philip M
12-12-2010, 08:50 AM
How long have they been "deprecated"?


The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.


In XHTML, this attribute is required and unnecessary.

Ah, that makes it very clear. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum