Hiding Scripts from Older Browsers

Older browsers don't always understand the script tag. If they don't, they'll just ignore it and display your script as if it were part of the body of the (X)HTML document. To keep that from happening, it's a good idea to use commenting to hide scripts from older browsers.

To hide scripts from older browsers:


After the initial script tag, type <!--.


Write the script as usual.


Right before the final script tag, type your scripting language's comments symbol. For JavaScript, type //. For VBScript, type ' (a single quotation mark). For TCL, type #.


If desired, add text to remind yourself why you're typing all these funny characters. Something like end comments to hide scripts will work just fine.


Type -->.

Figure 19.16. This is Mosaic 1. Because it doesn't understand the script tag, it ignores it and prints out the script as if it were regular text. Ugly!

Figure 19.17. This JavaScript script comes from Figure 20.11 on page 326. It preloads the images into cache to ensure speedy rollovers.

Figure 19.18. By commenting out the script, it is hidden from old browsers like this one. (Hey, it may not handle scripts, but this old version of Mosaic displays normal pages without trouble and runs on less than 1Mb of RAM.)


  • The code in step 1 and in step 5 is for hiding the script from the browsers. The code in step 3 is for keeping the final --> from being processed as part of the script, and thus must be specific to the particular scripting language you're using.

  • I have to admit I had a very hard time finding a browser old enough not to understand scripts. Hiding scripts from browsers was once a good idea, but I'm not sure it's essential any more.

  • External scripts (see page 313) are automatically hidden from old browsers. They simply don't follow the URL.

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net