Incorporating JavaScripts
JavaScript has a tremendous advantage over other methods of adding “beyond-HTML” features to your Web pages. It was designed for no other purpose, and it’s so tightly integrated with HTML that it’s a joy to use. The processing takes place in the visitors’ Web browsers, so it’s both fast for them and no problem for your Web server. You don’t have to understand the language to add other people’s scripts to your Web site. In many cases, no alterations to the code are needed. In some cases, you may have to change the filename or add some URLs to a list. Figure 8-3 shows the JavaScript Source at http://javascript.internet.com, one of the many places on the Web to get free JavaScript code.
Basic techniques
You need to add two things to your Web pages when you work with JavaScript: the script itself and something that triggers the script.
The script
The script has to go in the HEAD element of your Web page, like this skeleton script named whatever:
<HEAD> <Script Language="JavaScript"> /* You will usually find comments here. */ function whatever() { Actual code is found here. } </Script> </HEAD>

You can place scripts within the BODY element rather than the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access