PDA

View Full Version : JS that detects month and sends to approriate html page


Deathmaster213
02-18-2003, 12:17 AM
Hi there,

I'm a newbie and am hoping there may be a script in exsistance that would do the following when a text link is clicked:

I need a script attached to that link that detects the month and then loads an according page. I could do this manually by changing the link physically at the beginning of each month, but JS's are supposed to make our lives easier and more efficent right?

If anyone could help I'd be grateful.

Deathmaster213
02-18-2003, 12:33 AM
Ok, no sooner do I type that, I find a script that redirects depending on the day, so i'll try and modify it...

I'll be back when i discover it don't work :D

Deathmaster213
02-18-2003, 12:49 AM
Ok, I put this redirect in 'gigs.html' hoping it would then load the page relevant to the month. Simply swapping everything that was 'Day' for 'month' didn't seem to work. Can anyone enlighten me to where I went wrong (besides being born and attempting to do this)
--------------------------------------

SCRIPT LANGUAGE="Javascript"><!--

function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i];
}

var monthsArray = new;
initArray("January","February","March","April","May","June","July","August","September","October","November","December");
var month = new Date();
var lmonth=months[dateObj.getMonth() + 1]

if (month == "January") window.location = "gigs/jan.html"
if (month == "February") window.location = "gigs/feb.html"
if (month == "March") window.location = "gigs/mar.html"
if (month == "April") window.location = "gigs/apr.html"
if (month == "May") window.location = "gigs/may.html"
if (month == "June") window.location = "gigs/jun.html"
if (month == "July") window.location = "gigs/jul.html"
if (month == "August") window.location = "gigs/aug.html"
if (month == "September") window.location = "gigs/sep.html"
if (month == "October") window.location = "gigs/oct.html"
if (month == "November") window.location = "gigs/nov.html"
if (month == "December") window.location = "gigs/dec.html"
//-->
</SCRIPT>

Skyzyx
02-18-2003, 07:59 AM
Just create a new Date object, and get the month information. Remember that (usually) computers begin with 0, not 1, so instead of Jan-Dec being 1-12, it's 0-11. Hence, Jan is 0, Feb is 1, etc.


var gigs=new Date();

if (gigs.getMonth() == 0) location.href='gigs/jan.html';
else if (gigs.getMonth() == 1) location.href='gigs/feb.html';
else if (gigs.getMonth() == 2) location.href='gigs/mar.html';
else if (gigs.getMonth() == 3) location.href='gigs/apr.html';
else if (gigs.getMonth() == 4) location.href='gigs/may.html';
else if (gigs.getMonth() == 5) location.href='gigs/jun.html';
else if (gigs.getMonth() == 6) location.href='gigs/jul.html';
else if (gigs.getMonth() == 7) location.href='gigs/aug.html';
else if (gigs.getMonth() == 8) location.href='gigs/sep.html';
else if (gigs.getMonth() == 9) location.href='gigs/oct.html';
else if (gigs.getMonth() == 10) location.href='gigs/nov.html';
else if (gigs.getMonth() == 11) location.href='gigs/dec.html';