Why doesn't frameset onload event get called when each of the frames has an onload?

A

adnanx82

Hi,

I'm having a hard time figuring out why the onload event is not being
called for the frameset window in the following simple example. It is
being called for each of the component frames.

Here's the code:

mainpage.html:

<html>
<head><title>Main page</title></head>
<frameset rows="200,*,*">
<frame src="f1.html">
<frame src="f2.html">
<frame src="f3.html">
</frameset>
</html>
<script src = "common.js"></script>
------------
f1.html:

<html>
<head><title>Frame 1</title></head>
<body bgcolor="#ffcc00">
<center>THIS IS FRAME 1</center>
</body></html>
<script src = "common.js"></script>
------------
f2.html:

<html>
<head><title>Frame 2</title></head>
<body bgcolor="#6666ff">
<h2>This is Frame 2</h2>
</body></html>
<script src = "common.js"></script>
------------
f3.html:

<html>
<head><title>Frame 3</title></head>
<body bgcolor="#00ff66">
<center>..........frame 3</center>
</body></html>
<script src = "common.js"></script>
------------
common.js:

window.onload = on_load;
function on_load()
{
alert("in on load for " + self.document.location);
}

Thanks and appreciate any help,

-Adnan.
 
A

adnanx82

I think I figured out the problem. On a frameset page, you can't have
any other content, like the javascript src tag, and so the onload
method is not associated with the onload event for the frameset page.
 
K

kaeli

adnanx82 said:
I think I figured out the problem. On a frameset page, you can't have
any other content,

Sure you can.
I do.

Your problem is your script, not the frameset. The script is being called
after the page has loaded already, rendering it useless. Put the script
before the body/frameset tag (inside head), not after the end html tag.

--
 
A

adnanx82

Thanks for your reply. Do you know why it works for the frame pages
though? It seems like the onload event is being registered and called
for the frame pages even though the script is at the end, but not for
the frameset page.

Thanks,

-Adnan.
 
K

kaeli

adnanx82 said:
Thanks for your reply. Do you know why it works for the frame pages
though? It seems like the onload event is being registered and called
for the frame pages even though the script is at the end, but not for
the frameset page.

No, I don't, but I do know putting it in the head of the frameset solved the
problem.
I just tested it.

And you're right: it works fine for the other pages. I have no idea why.

--
 
T

Thomas 'PointedEars' Lahn

Thanks for your reply. Do you know why it works for the frame pages
though?

Though? Read again: It works for the frameset window as well but you
have positioned it wrong within the source code of its document.
It seems like the onload event is being registered and called
for the frame pages even though the script is at the end, but
not for the frameset page.

Every frame is a implemented as a separate Window object.


PointedEars
 

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

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top