...

View Full Version : Days in the week - JavaScript



ainsleyclark
05-08-2006, 01:46 PM
Hello,
I have a marquee in my site and and I have 7 corresponding html pages for 7 days of the week. I would like to have a day detection so (e.g) saturday.html will go in my iframe on my hompage, please make it idiot proof because im a rookie :thumbsup:

Mr J
05-08-2006, 01:58 PM
Please try the following


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script type="text/javascript">

currentDate=new Date()
currentDay=currentDate.getDay()

function loadIframe(){

switch(currentDay){

case 0:
loc="saturday.html "
break

case 1:
loc="monday.html "
break

case 2:
loc="tuesday.html "
break

case 3:
loc="wednsaday.html "
break

case 4:
loc="thursday.html "
break

case 5:
loc="friday.html "
break

case 6:
loc="saturday.html "
break

default:
alert("Oops")
}

parent.frames['iframe_name'].location=loc

}
</script>
</HEAD>
<BODY onload="loadIframe()">

<iframe name="iframe_name" src=""></iframe>

</BODY>
</HTML>

ainsleyclark
05-08-2006, 03:53 PM
still having some problems, it does not load:confused:
can i change it to a table instead? and can i have it just so it redirects it

Kor
05-08-2006, 03:55 PM
Thinking that the days of the week starts from 0 (Sun) in CPU, to speed the loading you may rename your pages:

0.html //sunday
1.html//monday
... and so on

and simply use

<script type="text/javascript">
var today=new Date();
var d=today.getDay();
onload= function(){
top.frames['frame_or_iframe_name'].location.href=d+'.html'
}
</script>

ainsleyclark
05-08-2006, 03:57 PM
ok lol got a code from another site, just gotanother quick question

<script language="javascript">

var today = new Date();
thisday = today.getDay();
var time = today.getHours();

if ((thisday == 1 && time >= 6) || (thisday==2 && time < 6)){
document.location="monday.html"
}

what does the this day and time mean?
cheers

Kor
05-08-2006, 04:02 PM
http://www.w3schools.com/js/js_obj_date.asp

felgall
05-08-2006, 10:17 PM
That script is changing the image at 6am each morning (based on the time set on your visitor's computer).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum