Web Development and Design Foundations with XHTML, 5th Edition

(Steven Felgate) #1

(^542) Chapter 14 A Brief Look at JavaScript







Save this file as documentwrite.html and view it in the browser. The text should display,
as shown in Figure 14.10. If the text does not display, open the Error Console and correct
any errors that appear.
FAQ
Why would I use document.writewhen I can just type the XHTML
code by itself?
You wouldn’t use document.writeto generate your Web page if you could just type the
XHTML code by itself. You would use document.writein conjunction with other techniques.
For instance, you might use JavaScript to detect the time of day, and if it is before noon use
document.writeto write “Good morning” to the document. If it is afternoon, write “Good
afternoon” to the document, and if it is after 6:00 p.m., write “Good evening” to the document.

14.6Events and Event Handlers


As the user is viewing a Web page, the browser detects mouse movement and events.
Eventsare actions taken by the Web page visitor, such as mouse clicks, page loads, or
form submissions. For instance, when you move your mouse pointer over a hypertext
link, the browser detects a mouseover event. Table 14.1 lists a few of the events and
their descriptions.

Figure 14.10
Firefox displaying
documentwrite.html


JavaScript can be seen in the source code. To confirm this, use the View, Page Source
menu commands to see the source code. Close the source code window when you have
finished viewing the code.
Free download pdf