How to Use Comment to Handle Browsers that do not support JavaScript

Leave a Comment

Browsers that do not support JavaScript will display JavaScript as page content. 

To prevent them from doing this and as a part of the JavaScript standard, the HTML comment tag should be used to “hide” the JavaScript. Just add an HTML comment tag <!-- before the first JavaScript statement, and an end-of–comment tag --> after the last JavaScript statement, like this:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>
The two forward slashes at the end of comment line (//) comprise the JavaScript comment symbol. This prevents JavaScript from executing the --> tag.

0 comments:

Post a Comment