I have recently inherited some web code and found that all the Java Script scripts are contained within HTML comment tags
For example:
<script type="text/javascript" language="javascript"><!--
function ValidateForm() { ... }//-->
As I understand it, this method prevented older, non-supported, browsers from interpreting your Java Script. However this is not something I was ever taught to do, and I wonder if this is now considered to be unnecessary, or is this still a common practice? If so, why?
Update: Thanks to kennebec for your advice to leave them in, which I have done for now, and thanks to Emmett also: I'll be sure to leave them out of any future code I write!
http://javascript.crockford.com/script.html:
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.
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