background
|
|
News
All in one Place
All of your regular news in one place.
More icon

Computer
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
Thau's JavaScript Tutorial
Lesson 1

by Thau!

Page 4 — Hiding JavaScript

The problem with the last example is that some old browsers don't understand the <script> tag. These browsers will treat your JavaScript just like HTML, so the page will come out like this:

//put up an alert box, to show how they work

alert("Soon, I will rebuild my browser!");

Congratulations!

Which isn't great. Luckily, there's a trick involving HTML comments:
    <html>
    <head>
    <title> blah blah blah </title>

    <script language="JavaScript">

    <!-- hide this stuff from other browsers

    YOUR SCRIPT HERE

    // end the hiding comment -->

    </script>

    </head>
    <body>
    etc., etc., etc.

The reasons why this trick works evaded me for a while, and you can use it without understanding why it works. However, if you really want to know, here's why the comment trick works.

OK, believe it or not, you're ready for your first JavaScript exercise.

Once you've conquered that assignment, take a minute to read our review of Lesson 1.

next page»