Using Variables and Built-in Functions to Update Your Web Pages Automatically
[next]
Using Variables and Built-in Functions to Update Your Web Pages Automatically
With JavaScript you can update the content on your pages automaticallyÂevery day, every hour, or every second. In this chapter, I'll focus on a simple script that automatically changes the date on your web page.
Along the way you'll learn:
|
Before getting into the nuts and bolts of functions and variables, let's take a look at a couple of examples of web pages that automatically update themselves, starting with the European Space Agency. As you can see in Figure 2-1, the ESA's home page shows you the current date. Rather than change the home page every day, the ESA uses JavaScript to change the date automatically.
An even more frequently updated page is the home page of the Book of JavaScript website, which updates the time as well as the date (see Figure 2-2). You don't have to sit in front of your computer, updating the dates and times on your websites. JavaScript can set you free! The ability to write HTML to web pages dynamically is one of JavaScript's most powerful features.
To understand how to update the date and time on the page, you'll first have to learn about variables, strings, and functions. Your homework assignment at the end of this chapter will be to figure out how to add seconds to the time.
[next]
URL: