1. Home
  2. Computing & Technology
  3. JavaScript

Time of Day Image

Part 1 : Introduction

One way that you can personalize your web page for individual visitors (without actually requiring any personal information about those visitors) is to display an image on your page that gives a rough indication of the time of day at that visitor's location. How do we do that? Well by using Javascript to grab the time from your visitors computer and then selecting one of serveral images to display based on that time.

This Javascript code actually uses eight images (these are supplied or you can substitute your own) to represent night, sunrise, early morning, morning, noom, afternoon, late afternoon, and sunset. One of these images will be displayed on your web page but which of the eight images gets displayed depends on what time it is according to the computer displaying the page.

Let's begin by looking at a sample page which shows the image that appears at this time of the day.

1 | 2 | 3 | 4 | 5

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript

©2008 About.com, a part of The New York Times Company.

All rights reserved.