Home Web Development Script to rotate website images based on Day of the Week

Script to rotate website images based on Day of the Week

552
3

This little script is very handy for displaying a different picture or other content piece on your website based on the day of the week.

<script>
var d=new Date();
var weekday=new Array(7);

weekday[0]=”<a href=’http://www.weburl.com/webpage#Sunday’><img src=’http://www.weburl.com/images/Sundayimg.jpg’ alt=” /></a>”;

weekday[1]=”<a href=’http://www.weburl.com/webpage#Monday><img src=’http://www.weburl.com/images/Mondayimg.jpg’ alt=” /></a>”;

weekday[2]=”<a href=’http://www.weburl.com/webpage#Tuesday><img src=’http://www.weburl.com/images/Tuesdayimg.jpg’ alt=” /></a>”;

weekday[3]=”<a href=’http://www.weburl.com/webpage#Webnesday><img src=’http://www.weburl.com/images/Wednesdayimg.jpg’ alt=” /></a>”;

weekday[4]=”<a href=’http://www.weburl.com/webpage#Thursday><img src=’http://www.weburl.com/images/Thursdayimg.jpg’ alt=” /></a>”;

weekday[5]=”<a href=’http://www.weburl.com/webpage#Friday><img src=’http://www.weburl.com/images/Fridayimg.jpg’ alt=” /></a>”;

weekday[6]=”<a href=’http://www.weburl.com/webpage#Saturday><img src=’http://www.weburl.com/images/Saturdayimg.jpg’ alt=” /></a>”;

document.write(“<form><strong>” + weekday[d.getDay()] + “</strong></form>”);
</script>

Note: Keep in mind, the “day of the week” may vary depending on the time zone of your host server’s physical location.  If there is a discrepancy and accuracy is critical to your project, then you’ll have to code in an offset (don’t forget daylight savings if you have it) if you want it to be true to your target time zone.

3 COMMENTS

  1. Very cool script! I would like to specify a different webpage for each different day of any month. For example:

    december 1, page=”http://infotopia.info/index_conoco_station.html”

    That way I could set up my front pages a month in advance.
    A possibility?

    Thanks,
    Michael Bell

  2. Sure can. here is one that should work for you. it grabs the day of the month and redirects the browser to that html page you want loaded for that day. I like it especially because you can set the next month up in advance from anywhere in the month without ever having to know what the full date will be. less chance of error from bad keystrokes. Just complete the code below for the rest of the days in the month and maybe have a generic page to load where it says error.html.

  3. var currentDate = new Date().getDate();
    if (currentDate === 1)
    window.location = “http://infotopia.info/index_conoco_station1.html”;
    else if (currentDate === 2))
    window.location = “http://infotopia.info/index_conoco_station2.html”;
    else if (currentDate === 3))
    window.location = “http://infotopia.info/index_conoco_station3.html”;
    else window.location = “error.html”;

LEAVE A REPLY

Please enter your comment!
Please enter your name here