Forum Moderators: open

Message Too Old, No Replies

JavaScript frame source/URL setting question

date-dependent frames in one HTML document

         

awefawe

9:51 am on Mar 11, 2009 (gmt 0)

10+ Year Member



Hi, I want to have a page with two frames, A and B, where
- A contains some external static page
- B contains a different external page, depending on the day of the week

and, if possible, I'd prefer to keep all of this in one *.htm file.

Here's what I have so far. The JavaScript runs, but it tells me "secfr is not defined."

<html>

[/code]
[code]<body>

<frameset cols="55%,45%">

<frame name="firstfr" id="firstfr" src="http://www.google.com/search?q=this+is+the+left+frame" />

<frame name="secfr" id="secfr" src="src="http://www.google.com/search?q=i+want+day+number+here" />

</frameset>

</body>

[/code]
[code]<script language = "JavaScript" type="text/javascript">

var now = new Date();

var myArray = new Array("1","1","2","3","4","5","1");

var str = myArray[now.getDay()];

secfr.location = "http://google.com/search?q=the+day+is+num+" + str + "!";

</script>

[/code]
[code]</html>

Oh, and things I've already tried:
- "src" instead of "location"
- parent.secfr
- parent.frames[2].secfr
- window.secfr
- top.secfr

[edited by: awefawe at 9:54 am (utc) on Mar. 11, 2009]

awefawe

9:53 am on Mar 11, 2009 (gmt 0)

10+ Year Member



(Whoops, didn't notice there was an edit post feature until after posting this.)

daveVk

11:54 am on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

document.getElementById( "secfr" ).src =

I assume src="src=" is a transcription error

Remove the body tags, frameset is replacement for body.

Alternative would be to replace

<frame name="secfr" id="secfr" src="src="http://www.google.com/search?q=i+want+day+number+here" />

with

<script language = "JavaScript" type="text/javascript">
var now = new Date();
var myArray = new Array("1","1","2","3","4","5","1");
var str = myArray[now.getDay()];
document.write( '<frame name="secfr" id="secfr" src="http://google.com/search?q=the+day+is+num+' + str + '!" />';
</script>

awefawe

3:13 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



Hm, is this what you meant?
[mysite.verizon.net...]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

 "http://www.w3.org/TR/html4/loose.dtd">

<html>

[/code]
[code]<frameset cols="55%,45%">

<frame name="firstfr" id="firstfr" src="http://www.google.com/search?q=this+is+the+left+frame" />

<frame name="secfr" id="secfr" src="http://www.google.com/search?q=i+want+day+number+here" />

</frameset>

[/code]
[code]<script language="JavaScript" type="text/javascript">

<!--

var now = new Date();

var myArray = new Array("1","1","2","3","4","5","1");

var str = myArray[now.getDay()];

alert(str); /* just to test if script is running at all */

document.getElementById( "secfr" ).src = "http://google.com/search?q=the+day+is+num+' + str + '!";

//-->

</script> 

[/code]
[code]</html>

I can't seem to get the script to execute at all...

awefawe

4:03 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



Got it! Stuck the <script> in <head> at the beginning, then called the function using the onload attribute in the frameset.

Thanks a lot for your help!