Datasheet
Chapter 1: Introduction to JavaScript
19
On Windows, Internet Explorer comes pre - installed. You can choose to upgrade to the latest version or
leave it the way it came. You should then also download Firefox from
http://www.getfirefox.com
and Safari from
http://www.apple.com/safari/ . Google Chrome can be downloaded at
http://chrome.google.com and Opera from http://www.opera.com .
On Mac, you ’ ll want to download Firefox from the same location, and, of course, Safari comes
pre - installed. For testing Internet Explorer, we suggest you run copies inside a Windows VMWare or
Parallels image right on your desktop.
In Chapter 21, I ’ ll talk more about tools that can assist you in debugging your applications inside a
browser. For now, just make sure you can load a test page on your computer using whatever browser
you have handy at least by using the file:// technique mentioned earlier.
Your First JavaScript Application
This chapter provides a lot of background on the history and role that JavaScript plays in development,
but no introduction on a programming language would be complete without one bare - bones example.
Remember that all the examples in this book can be found online at
http://wroxjavascript.com .
There are several ways to augment a web page with JavaScript. One is to use the HTML tag
< script > to
indicate a portion of the page for script. This is known as a script block . When a browser spots a script
block in a page, it does not draw its contents to the page. Instead, it “ parses ” its contents as a script block
in the order that it appears . Generally speaking, if there are two script blocks on a page, the top one will
execute first. You are allowed to put script blocks in the
< head > area of the page and also in the < body >
area. Blocks in the header execute before ones in the body.
I ’ ll talk more about
< script > tags in Chapter 3 because there are a few more things you should know
about them. For now, take a look at the HTML page that follows with some in - line JavaScript code.
< html >
< body >
< h1 > Hello World! < /h1 >
< script type=”text/javascript” >
var today = new Date();
document.write(“ < p > Today is: “ + today.toString() + “ < /p > ”);
< /script >
< /body >
< /html >
CH001.indd 19CH001.indd 19 6/25/09 7:53:23 PM6/25/09 7:53:23 PM