Forum Moderators: mack

Message Too Old, No Replies

Loading page in a frameset based on time of day

How to change the page loaded depending on the time of day

         

inarbeth

8:03 pm on Sep 14, 2003 (gmt 0)

10+ Year Member



I am new to this forum so I hope I am posting in th eright place. I am not very knowledgeable about javascript. I have been searching the web for a while but cannot find an answer to this question.

I have a web page with a frame with contents on the left and a main page. There are links to 4 pages that can be loaded in the main page. What I want to do is have the page that is first loaded into the main page vary according to the time of day. If it's before 3pm then Page1 to load, between 3 and 6 Page2, between 6 and 9 Page3 and between 9 and midnight Page4.

I don't want the user to have to click to invoke this, simply that the page loads when first browsed or on a refresh.

claus

8:23 pm on Sep 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld inarbeth :)

I'm not sure i should be telling you this due to the title of the forum, but if you have access to mod_rewrite and ".htaccess" on your server, your recipe is here:

[engelschall.com...]

/claus

inarbeth

7:13 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



Sorry claus I don't know where to begin with this. The web site is my own so I have full access but I have no idea what mod_rewrite is. One idea I had was to have a blank page in the main frame and use an automatic re-direct on zero seconds and have that controlled by javascript.

korkus2000

7:22 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld inarbeth,

Try something like this in the frameset:

day=new Date();
x=day.getHours();

if(x>=0 && x<15){
top.framename.location = 'page1.htm';
} else if(x>=15 && x<18) {
top.framename.location = 'page2.htm';
} else if(x>=18 && x<21) {
top.framename.location = 'page3.htm';
} else if (x>=21 && x<24) {
top.framename.location = 'page4.htm';
}

g1smd

8:53 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you want this based on the time of day at the server location, or the time of day at the place where your visitor is (because for the latter, at any one moment, there is a different time of day in different countries)?

inarbeth

9:46 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



I want time of day based on the user's own time, e.g. taken from his own computer.
I'll give korkus2000's suggestion a go.

inarbeth

6:47 am on Sep 20, 2003 (gmt 0)

10+ Year Member



Having a problem guys. Not sure if there is any connection but as soon as I tried the script out front Page 2002 started playing up and now I cannot Preview. The preview tab switches over but none of the hyperlinks - either to other pages or from thumbnails to pictures - work. I have deleted the script, repaired Front Page and finally uninstalled and reinstalled it, but still the same problem. Can anyone help?

claus

9:15 am on Sep 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This sounds like a software problem. I don't think it's related to the javascript posted above, such a script should not be able to make a software package go nuts. It could be most anything on your system that caused this, i'm afraid - if you've removed or installed any programs about the same time, they are more likely to be guilty. Spyware and such from the internet can also cause chaos in some windows programs.

/claus

inarbeth

5:28 am on Sep 21, 2003 (gmt 0)

10+ Year Member



Hi claus
I eventually searched the MS knowledge base and straightaway found this article
[support.microsoft.com...]

which solves the problem :-)

I had forgotten about the Microsoft update. I pity the thousands (hundreds of thousands?) of FrontPage users whose product is now b**gered until they find out about this!

inarbeth

7:30 am on Sep 21, 2003 (gmt 0)

10+ Year Member



Now that I've got FrontPage working again, I'm still having trouble with my script. The frame I'm trying to work on is here: <snip>

I tried korkus2000's idea and changed my frames page html to:

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Clare World Music Festival 12 July 2003</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

day=new Date();
x=day.getHours();

// - End of JavaScript - -->
</SCRIPT>
</head>
<frameset cols="190,*">
<frame name="contents" target="main" src="Clarecontents.htm">
<frame name="main"
if(x>=0 && x<15){
top.framename.location = 'Ezio1.htm';
} else if(x>=15 && x<18) {
top.framename.location = 'WorxFM1.htm';
} else if(x>=18 && x<21) {
top.framename.location = 'Osibisa1.htm';
} else if (x>=21 && x<24) {
top.framename.location = 'Showaddywaddy1.htm';
}scrolling="auto">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>

</html>

but this does not work.

The frameset which does work is:
...

<frameset cols="190,*">
<frame name="contents" target="main" src="Clarecontents.htm">
<frame name="main" src="WorxFM1.htm" scrolling="auto">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>

...

What am I doing wrong? Thanks for your patience.

[edited by: engine at 6:11 pm (utc) on Sep. 21, 2003]
[edit reason] No urls, thanks. See TOS [webmasterworld.com] [/edit]

claus

12:21 pm on Sep 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Part of your script has been placed outside the <SCRIPT> tags, specifically this part:

if(x>=0 && x<15){ 
top.framename.location = 'Ezio1.htm';
} else if(x>=15 && x<18) {
top.framename.location = 'WorxFM1.htm';
} else if(x>=18 && x<21) {
top.framename.location = 'Osibisa1.htm';
} else if (x>=21 && x<24) {
top.framename.location = 'Showaddywaddy1.htm';
}

Try moving it inside the script tags, below the two lines that are there already. Just leave the working part as it is, with this line:

<frame name="main" src="WorxFM1.htm" scrolling="auto">

/claus

inarbeth

6:20 pm on Sep 21, 2003 (gmt 0)

10+ Year Member



Hi claus
I've done that but I get this error message:

Line: 20
Char: 1
'top.framename' is null or not an object
Code: 0

claus

2:09 pm on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, i didn't see that. I think "framename" should be the name of your frame from this line of code:

<frame name="main" src="WorxFM1.htm" scrolling="auto">

-ie. "main", so try replacing "framename" with "main" in the javascript code - perhaps that will do the trick. Like this:

top.main.location = 'Ezio1.htm'; 

inarbeth

7:14 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



Still getting this error message:

Line: 20
Char: 1
'top.main' is null or not an object
Code: 0

claus

7:34 pm on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem, we'll just have to see if we can call the frame another way. Try this syntax in stead, it might be better:

window.frames["main"].location = 'Ezio1.htm'; 

inarbeth

8:27 pm on Sep 22, 2003 (gmt 0)

10+ Year Member



Getting this message:
Line: 20
Char: 1
'windows.frame.main' is null or not an object
Code: 0

Just to check, my code now reads:

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

day=new Date();
x=day.getHours();
if(x>=0 && x<15){
window.frames["main"].location = 'Ezio1.htm';
} else if(x>=15 && x<18) {
window.frames["main"].location = 'WorxFM1.htm';
} else if(x>=18 && x<21) {
window.frames["main"].location = 'Osibisa1.htm';
} else if (x>=21 && x<24) {
window.frames["main"].location = 'Showaddywaddy1.htm';
}

// - End of JavaScript - -->
</SCRIPT>
</head>
<frameset cols="190,*">
<frame name="contents" target="main" src="Clarecontents.htm">
<frame name="main" src="WorxFM1.htm" scrolling="auto">
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>

</html>

g1smd

10:11 pm on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is the target="main" a part of the problem?

claus

4:41 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps it's a timing problem. At the time the browser reads the javascript, the frame doesn't exist, as the script is in the <head> section, and the frameset is outside bounds (not in <head> and not in <body>).

Modify the beginning of your javascript, so that it looks like this (i've included the first line of javascript code as it look s now):

<script type="text/javascript" language="JavaScript"><!--
function setFrame(){
day=new Date();

Then, modify the end of your javascript, so that it looks like this (i've included the last line of javascript code as it looks now):

window.frames["main"].location = 'Showaddywaddy1.htm'; 
}
}
//--></script>

Then, move your <body> tag up, so that it's immediately after your </head> tag and modify it to look like this (i've included the </head> tag, all on one line):

</head><body onLoad="setFrame()">

Then, move your </body> tag down, so that it's immediately before your </html> tag, like this:

</body></html>

Also, move your </frameset> tag, so that it's immediately before your <noframes> tag, like this:

</frameset><noframes>

After these changes, i really think your code should work.

inarbeth

3:42 pm on Sep 27, 2003 (gmt 0)

10+ Year Member



Sorry to come back to this but I have been away for a few days.

I'm still getting the error message:
'windows.frame.name' is null or not an object

I've modified the code so it reads:
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Clare World Music Festival 12 July 2003</title>
<script type="text/javascript" language="JavaScript"><!--
function setFrame(){
day=new Date();
x=day.getHours();
if(x>=0 && x<15){
window.frames["main"].location = 'Ezio1.htm';
} else if(x>=15 && x<18) {
window.frames["main"].location = 'WorxFM1.htm';
} else if(x>=18 && x<21) {
window.frames["main"].location = 'Osibisa1.htm';
} else if (x>=21 && x<24) {
window.frames["main"].location = 'Showaddywaddy1.htm';
}
}
//--></script>
</head>
<body onLoad="setFrame()">
<frameset cols="190,*">
<frame name="contents" target="main" src="Clarecontents.htm">
<frame name="main" src="WorxFM1.htm" scrolling="auto">
<noframes>

<p>This page uses frames, but your browser doesn't support them.</p>

</frameset></noframes>
</body>
</html>

jimbeetle

4:26 pm on Sep 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi inarbeth,

I'm not much of a js person but I think I see an approach to working this problem. Hopefully somebody with good js knowledge will come along and flesh out the details.

Maybe move the entire script to the body section and use document.write in the if...else statements. Something like:

<frameset cols="190,*">
<frame name="contents" target="main" src="Clarecontents.htm">

<script type="text/javascript" language="JavaScript">
<!--
day=new Date();
x=day.getHours();

if(x>=0 && x<15){
document.write(<frame name='main' src='Ezio1.htm' scrolling='auto'>)

} else if(x>=15 && x<18) {
document.write(<frame name='main' src='WorxFM1.htm' scrolling='auto'>)

} else if (x>=18 && x<21) {

document.write(<frame name='main' src='Osibisa1.htm'; scrolling='auto'>)

} else if (x>=21 && x<24) {
document.write(<frame name='main' src='Showaddywaddy1.htm'; scrolling='auto'>)

//--></script>

That's the idea. Now if somebody can come along and correct that to get it to work it might do it.

claus

5:37 pm on Sep 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, it's me that have messed up the syntax, and i'm really sorry about that. The thing is, you can address the frame "main" in two ways:

  • window.main.location = 'Ezio1.htm';

  • window.frames[1].location = 'Ezio1.htm';

Similarly, the frame named "contents" can be called this way.

  • window.contents.location = 'Ezio1.htm';

  • window.frames[0].location = 'Ezio1.htm';

So i think you will get it working by using any of the two syntaxes from the first example.

By the way, you still have the last tags i mentioned in post 18 messed up, i see. It would be a good idea to edit it:

Also, move your </frameset> tag, so that it's immediately before your <noframes> tag, like this:

</frameset><noframes>

/claus

inarbeth

2:41 pm on Oct 4, 2003 (gmt 0)

10+ Year Member



Sorry it's not working. Can we try Plan B? If I have an automatic re-direct from the main page based on the time of day, I should achieve the same result. I have searched for a script to redirect based on the time of day but cannot find one and so have devised the following but it does not work. Can anyone help?

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>

<SCRIPT LANGUAGE="JavaScript">

<!--
var d = new Date()
var time = d.getHours()
if (time<12)
document.location="Page1.htm";
else if (time<16)
document.location="Page1.htm";
else if (time<20)
document.location="Page3.htm";
else
document.location="Page4.htm";
//-->
</script>

</head>
<body>

</body>
</html>

claus

2:55 pm on Oct 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As usual, it seems i've forgotten something. In stead of
.location
you need to write:

.location.href

I think plan A and B should both work if you do this. Sorry to have messed up like this.

/claus

inarbeth

3:21 pm on Oct 4, 2003 (gmt 0)

10+ Year Member



Sorry Claus
I'm still getting the error message. Could I trouble you to edit and re-paste the whole of my code. I'm sorry this is taking so long.

claus

3:38 pm on Oct 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> edit and re-paste

Yes of course, here's plan B - you forgot a few brackets. It works for me now:

------------------------------------------------------------------

<html><head><title>hi!</title> 
<script type="text/javascript"><!--
var d = new Date()
var time = d.getHours()
if (time<12) {
document.location.href="http://www.google.com/search?q=12";
}else if (time<16) {
document.location.href="http://www.google.com/search?q=16";
}else if (time<20) {
document.location.href="http://www.google.com/search?q=20";
}else {
document.location.href="http://www.google.com/search?q=else";
}
//--></script>
</head><body>
hi!
</body></html>

------------------------------------------------------------------

Note that i've included the full url, this might be necessary. You should consider what you write in the <body> and <title> as google will not be redirected, in stead it will index what you write in those tags (currently "hi!").

/claus

inarbeth

4:23 pm on Oct 4, 2003 (gmt 0)

10+ Year Member



Thanks Claus - it works.

Next I'm going to change one picture out of many on my home page depending on the time.