Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q467 Is there some way to load a different home page each time someone comes to the site, or cycle through several different versions?

You are here: irt.org | FAQ | JavaScript | Random | Q467 [ previous next ]

It would be possible to store a number in a cookie that would indicate to a user that later returns to display a different page - although not everyone accepts cookies. An easier approach would be to show a page depending on the time of day. The following assumes that there are pages index1.html through to index24.html

<SCRIPT LANGUAGE="JavaScript"><!--
var now = new Date();
var hour = now.getHours() + 1;

if (document.images)
    location.replace('http://www.somewhere.com/index' + hour + '.html');
else
    location.href = 'index' + hour + '.html';
//--></SCRIPT>

Note: in Opera replace() will work, but only with absolute URL's.

©2018 Martin Webb