Friday, February 13, 2009
by
ASP.NET AJAX Team
|
Sometimes we need to hide the JavaScript code from the old browsers
that do not support it.
To prevent old browsers from displaying your JS code, do the
following:
Immediately after the opening <script> tag, put a one-line
HTML-style comment without the closing characters, so that the first
two lines of your script would look like this:
<script language="JavaScript">
<!--
At the end of your script, put the following two lines:
//-->
</script>
Thus, your HTML file will contain the following fragment:
| <script
language="JavaScript">
<!--
Put your JS code here. Old
browsers will treat it as regular
HTML comment. //-->
</script> |
Old browsers will treat your JavaScript code as one long
HTML comment. On the other hand, new JavaScript-aware browsers
will normally interpret the code between the tags <script>
and </script> (the first and last lines of the code will be
treated by the JavaScript interpreter as one-line comments).
Embedding JavaScript in HTML