1. Home
  2. Computing & Technology
  3. JavaScript

Time of Day Image
Introduction

By Stephen Chapman, About.com

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.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.