Forum Moderators: mack
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.
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
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';
}
/claus
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!
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]
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
<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';
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>
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.
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>
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.
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
<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>
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