Chapter 6 -- Introduction to Scripting

Chapter 6

One of the most important and exciting innovations to traditional Web browsers was the addition of scripting. Through scripts, Web designers can add a level of interactivity and sophistication to their Web pages that is typically found only in advanced applications. Scripts are blocks of program code that are "embedded" in Web pages and interpreted at run time. This simply means that the text file containing the HTML also contains some additional text that issues commands to the browser.

In the same way that Microsoft Internet Explorer 5 interprets HTML to determine what to display on the screen, it also interprets any script it encounters to determine what actions to take. This script must be written in one of a set of specific programming languages that the browser understands. For example, the Web page shown in Code Listing 6-1 contains some simple script that causes an image to change when the user clicks it.

Code Listing 6-1.

 <HTML> <HEAD> <TITLE>Listing 6-1</TITLE> </HEAD> <BODY> <IMG ID="MyImage" SRC="oldpic.gif" onclick="MyImage.src=`newpic.gif'"> </BODY> </HTML> 

This chapter offers an overview of scripting and how it relates to the Dynamic HTML Object Model described in Chapter 5. We'll examine some basic examples of scripting, such as the one that appears in Code Listing 6-1. The remaining chapters in Part 2 provide full coverage of scripting techniques.

NOTE
Netscape Navigator (through at least version 4) does not support as full a Dynamic HTML Object Model as Internet Explorer. For example, it does not support the onclick event with images. As a result, Code Listing 6-1 does not change the image when clicked in Navigator, though it also does not cause any errors. The file IENSSWAP.htm in the crosplat folder on the companion CD demonstrates a complete cross browser image swapping solution. The solution is somewhat code intensive, however, and so is not appropriate for an introductory discussion of scripting. More cross browser development tricks are presented throughout this book and particularly in Chapter 23.



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

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