473,499 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help - can't get the right frame reference

I have this arrangement of frames:

<html><head><script type="text/javascript"></script></head>

<frameset rows="100,*">
<frameset cols="135,*,165">
<frame name="logo" src="some.html" scrolling="No">
<frame name="title" src="someother.html" scrolling="No">
<frame name="nav" src="yetmore.html" scrolling="No">
</frameset>
<frameset>
<frame name="mainpage" scrolling="No">
</frameset>
</frameset>
</html>

I want to load some html into the frame "mainpage". How do I refer to
this frame from within my javascript up there in the header? I've tried
a myriad of things like:

<script type="text/javascript">

window.frames["mainpage"].location.href = "evenmore.html";

</script>

but it always says "object needed". I can't quite see how to string
together the object reference I need and would appreciate a pointer.

Thanks,

-- tim
Jul 23 '05 #1
5 1767
Tim Streater wrote:
I have this arrangement of frames:

<html><head><script type="text/javascript"></script></head>

<frameset rows="100,*">
<frameset cols="135,*,165">
<frame name="logo" src="some.html" scrolling="No">
<frame name="title" src="someother.html" scrolling="No">
<frame name="nav" src="yetmore.html" scrolling="No">
</frameset>
<frameset>
<frame name="mainpage" scrolling="No">
</frameset>
</frameset>
</html>

I want to load some html into the frame "mainpage". How do I refer to
this frame from within my javascript up there in the header? I've tried
a myriad of things like:

<script type="text/javascript">

window.frames["mainpage"].location.href = "evenmore.html";

</script>

but it always says "object needed". I can't quite see how to string
together the object reference I need and would appreciate a pointer.

Thanks,

-- tim

When you place JavaScript in the header, it is executed prior to the
page loading. In this case, you are attempting to access a frame which
doesn't yet exist, because it hasn't yet gotten to that section of the
HTML code.

Using an onload will wait until the document is loaded before
attempting to access an element, thereby avoiding the problem of
attempting to access an element before it exists.

window.onload = function () {
alert( window.frames["mainpage"].location.href );
}
Alternately, you may try this:
function testThis() {
alert( window.frames["mainpage"].location.href );
}
<frame name="mainpage" scrolling="No" onLoad=testThis()>

There are other ways to do it, but you get the idea.

Jul 23 '05 #2
VK
In IE model frameSet doesn't have "frames" collection anymore as well
as a bunch of other window properties. Other browsers did not get
broken enough yet I guess to take it out.

Jul 23 '05 #3
VK wrote:
In IE model frameSet doesn't have "frames" collection anymore as well
as a bunch of other window properties. Other browsers did not get
broken enough yet I guess to take it out.


Which version of IE? The code above I tested in IE 6.0.2800.1106, SP1.

Jul 23 '05 #4
VK
> In IE model frameSet doesn't have "frames" collection anymore

my bs ^ 2 (bs in square)
The only weak excuse that I did not use frames for several years by
now.

<html>
<head>
<title>Top Frameset</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>

function test() {
//alert(self.document.title);
alert(self.frames['f2'].document.getElementsByTagName('P')[0].innerHTML);
}
window.onload=test;
</script>
</head>

<frameset cols="50%,*">
<frame name="f1" src="frame1.html">
<frame name="f2" src="frame2.html">
</frameset>

</html>

Jul 23 '05 #5
In article <11**********************@g49g2000cwa.googlegroups .com>,
"Random" <ra*******@gmail.com> wrote:
Tim Streater wrote:
I have this arrangement of frames:

<html><head><script type="text/javascript"></script></head>

<frameset rows="100,*">
<frameset cols="135,*,165">
<frame name="logo" src="some.html" scrolling="No">
<frame name="title" src="someother.html" scrolling="No">
<frame name="nav" src="yetmore.html" scrolling="No">
</frameset>
<frameset>
<frame name="mainpage" scrolling="No">
</frameset>
</frameset>
</html>

I want to load some html into the frame "mainpage". How do I refer to
this frame from within my javascript up there in the header? I've tried
a myriad of things like:

<script type="text/javascript">

window.frames["mainpage"].location.href = "evenmore.html";

</script>

but it always says "object needed". I can't quite see how to string
together the object reference I need and would appreciate a pointer.

Thanks,

-- tim

When you place JavaScript in the header, it is executed prior to the
page loading. In this case, you are attempting to access a frame which
doesn't yet exist, because it hasn't yet gotten to that section of the
HTML code.

Using an onload will wait until the document is loaded before
attempting to access an element, thereby avoiding the problem of
attempting to access an element before it exists.

window.onload = function () {
alert( window.frames["mainpage"].location.href );
}
Alternately, you may try this:
function testThis() {
alert( window.frames["mainpage"].location.href );
}
<frame name="mainpage" scrolling="No" onLoad=testThis()>

There are other ways to do it, but you get the idea.


Thanks for this pointer. Putting the onload in the frame itself did not
seem to work (the onload was not triggered, I suppose because nothing
had been loaded) so I put it in the outer frameset and this works fine
on Safari 1.3, and recent IE and Netscape under XP.

So I suppose the lesson is that timing is everything.

-- tim
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1540
by: aToaster | last post by:
Hey guys, I'm just getting the hang of Python and Tkinter and I could use some help. I wrote most of the gui for my calculator program, well I haven't gotten around to putting in the...
7
1956
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it...
14
2118
by: TrvlOrm | last post by:
OK. After much playing around, I managed to get my frame page this far.. see code below. BUT...there are still errors with it, and what I would like to have happened is this: 1) On the Left...
26
45464
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
4
1368
by: gokcemutlu | last post by:
I want to trace a function while it executes and keep its local variables as states. In trace function all the things work well but after all when I print states, they are all the same. I couldn't...
36
3066
by: aljamala | last post by:
Hi, I keep getting this warning on a page, but I do not know what the problem is...does anyone have an idea about what could be wrong? line 88 column 7 - Warning: missing </formbefore <td> it...
5
2137
by: saytri | last post by:
Hi i have this project were i have to do a quiz. i wrote the questions in a textfile and i called them through java. I have also made a menu to choose which type of quiz. But before accessing the...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.