If you are presenting your HTML on the web to an audience that may use browsers that cannot cope with the <SCRIPT> tag, then you will need to hide the script inside the <SCRIPT> block. This is done by placing HTML comment tags around the script code.
This depends on the JavaScript interpreter providing some non-standardized behavior. That is, it needs to recognize the HTML comment opening tag as being some valid syntax, even though it is not really legal.
Beware that the closing HTML comment tag is placed on a line that itself is a JavaScript comment. However, you must also make sure that the closing </SCRIPT> tag is placed on a line of its own or the interpreter cannot see it and the <SCRIPT> block then becomes unterminated.
<SCRIPT> <!-- // Hide from older browsers alert("some script here"); // end hiding --> </SCRIPT>
See also: | COMMENT object, Pitfalls |
Prev | Home | Next |
Hidden.value | Up | Hierarchy of objects |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |