• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Start Me Up! > Hiding Scripts from Old Browsers

Hiding Scripts from Old Browsers

Older browsers, which include Netscape 1.x, Microsoft Internet Explorer versions 3 and earlier, and the America Online browser before version 4, don't understand JavaScript. While well-behaved browsers are supposed to ignore everything between tags they don't understand, not all of them do. There's a technique (as shown in Script 2.2) that will fool these backward browsers into thinking that the contents of your script are actually HTML comments, which they will then ignore. A comment is text enclosed in special tags; any text—notes, clarifications, explanations of code, whatever—inside the tags gets ignored by the browser.

To hide JavaScript from old browsers:

1.
								<!-- Hide script from old browsers
							



This line opens the HTML comment with the <!--.

2.
								document.write("Hello, world!")
							



Here's the actual JavaScript, as in the previous example.

3.
								// End hiding script from old browsers -->
							



This line starts with // which signifies a JavaScript comment, and ends with --> which ends an HTML comment.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint