Controlling frames with javascript

B

Big Daddy

I have a simple page with 2 frames and want to be able to change the
source for the frames with javascript. See this source:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
window.frames[0].location='something';
window.frames[1].location='whatever';
</SCRIPT>
</HEAD>
<frameset ID="aFrameset" rows='103px,100%'>
<frame noresize='0' scrolling='no' name='top' id='top'>
<frame noresize='0' scrolling='yes' name='bottom' id='bottom'>
</frameset>
</HTML>

The code causes an error because the frames array doesn't have any
frames in it. I try to access the frames using their name or ID
instead (e.g. getElementById), but that doesn't work either. I have
tried to move the javascript to be after the frames declaration, but
it doesn't get called at all. I am using IE 7.

Any ideas how I can do this? thanks in advance,
John
 
T

Tim Streater

Big Daddy said:
I have a simple page with 2 frames and want to be able to change the
source for the frames with javascript. See this source:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
window.frames[0].location='something';
window.frames[1].location='whatever';
</SCRIPT>
</HEAD>
<frameset ID="aFrameset" rows='103px,100%'>
<frame noresize='0' scrolling='no' name='top' id='top'>
<frame noresize='0' scrolling='yes' name='bottom' id='bottom'>
</frameset>
</HTML>

The code causes an error because the frames array doesn't have any
frames in it. I try to access the frames using their name or ID
instead (e.g. getElementById), but that doesn't work either. I have
tried to move the javascript to be after the frames declaration, but
it doesn't get called at all. I am using IE 7.

Any ideas how I can do this? thanks in advance,
John

Probably when the JS executes, the frames don't exist yet. You want to
put:

onload="initialise();"

or whatever in your <frameset> declaration, and then put the code in
your initialise() function.
 
M

Martin Honnen

Big said:
I have a simple page with 2 frames and want to be able to change the
source for the frames with javascript. See this source:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
window.frames[0].location='something';
window.frames[1].location='whatever';

You need to wait for the document to load e.g.
window.onload = function()
{
window.frames[0].location.href = 'doc1.html';
window.frames[1].location.href = 'doc2.html';
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top