Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Controlling frames with javascript

Reply
Thread Tools

Controlling frames with javascript

 
 
Big Daddy
Guest
Posts: n/a
 
      04-22-2009
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
 
Reply With Quote
 
 
 
 
Tim Streater
Guest
Posts: n/a
 
      04-22-2009
In article
<(E-Mail Removed)>,
Big Daddy <(E-Mail Removed)> wrote:

> 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.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-22-2009
Big Daddy wrote:
> 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';
};

> </SCRIPT>




--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
Big Daddy
Guest
Posts: n/a
 
      04-22-2009
Thanks to both of you that responded. It worked!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Frames or not Frames... Ale HTML 17 08-05-2005 12:10 AM
Frames:Controlling another frame w/ history.go(-1) Jenn Javascript 2 08-02-2004 08:55 AM
Link needed to go from a non-frames page to a Frames page, and load a particular frame. How? - Newbe Philip HTML 3 06-28-2004 03:06 PM
From Frames to no frames? Powerslave2112 HTML 2 01-20-2004 10:30 PM
controlling redirection within frames headware ASP .Net 0 08-04-2003 11:46 PM



Advertisments