Web Development and Design Foundations with XHTML, 5th Edition

(Steven Felgate) #1

(^450) Chapter 11 Web Multimedia and Interactivity
run outside of a Web browser. JavaScript statements can be placed in a separate file (with
a.js extension) accessed by a Web browser, but JavaScript statements are more commonly
embedded directly in the Web page along with the XHTML. In either case, the Web
browser interprets the JavaScript statements. JavaScript is considered to be a client-side
scripting language—it runs on the Web client (the browser) and not the Web server. Note
that although some Web servers (such as the Sun Java System Web server) can process
server-side JavaScript, the language is most commonly used for client-side scripting.
Figure 11.16
JavaScript is used
to swap images on
this page
FAQ
Don’t all browsers support JavaScript?
Most modern browsers support JavaScript. However, they also offer the option to disable
JavaScript, and some assistive technologies such as screen readers may not support
JavaScript. You can’t count on every person who visits your Web site to allow JavaScript. It’s a
good idea to offer your Web page visitors an alternative (plain text links, a phone number to
call, and so on) if features of your Web site are dependent on JavaScript.


Common Uses of JavaScript

JavaScript is often used to respond to events such as moving the mouse, clicking a button,
and loading a Web page. Figure 11.16 shows two screenshots from the Library of Congress
Exhibitions site (http://www.loc.gov/exhibits). Notice how the image at the right is
different depending on the position of the mouse. This “image swapping” is accomplished
by using JavaScript. This technology is also often used to edit and verify information
on XHTML form elements such as text boxes, check boxes, and radio buttons. JavaScript
can be used to create pop-up windows, display the current date, perform calculations, and
so on. There is an introduction to coding JavaScript in Chapter 14.
Free download pdf