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.

Figure 8-3. The JavaScript Source gives you 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 ...

Get Building a Web Site For Dummies®, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.