Calling onunload in frameset

A

Andrew Poulos

In a frameset I have this:

window.onload = function() {
frames[1].onunload = function() {
alert('I'm going now');
}
}

when frames[1] unloads I'm expecting the alert to be called but it never
does. If, instead, I put this into frames[1] it does call the alert:

window.onunload = function() {
alert('I'm also going now');
}

How can I get it to work from the frameset?

Andrew Poulos
 
C

Csaba2000

As I understand your question, your example code is saying, put an onload
handler on my frame as I'm [= the frameset] unloading myself. But by then
I'd expect my frame to already be gone. To double check this, also put
an alert before the frames[1].onunload = function() ... statement.

Csaba Gabor from Vienna
 
A

Andrew Poulos

Csaba2000 said:
As I understand your question, your example code is saying, put an onload
handler on my frame as I'm [= the frameset] unloading myself. But by then
I'd expect my frame to already be gone. To double check this, also put
an alert before the frames[1].onunload = function() ... statement.

Csaba Gabor from Vienna

Andrew Poulos said:
In a frameset I have this:

window.onload = function() {
frames[1].onunload = function() {
alert('I'm going now');
}
}

when frames[1] unloads I'm expecting the alert to be called but it never
does. If, instead, I put this into frames[1] it does call the alert:

window.onunload = function() {
alert('I'm also going now');
}

How can I get it to work from the frameset?

Andrew Poulos
I think I didn't state my problem unambiguously. Let me try again:

Without putting any script into each frame how can a frameset detect
events, such as onload and onunload, from each frame (as opposed to the
entire frameset)?

Andrew Poulos
 
C

Csaba2000

I would try (not that I have, mind you):
Put into the <head> section of the frameset page:
<script type='text/javascript'>
function myFunc() { alert("Here I am"); }
top.onload = top.setTimeout(function() {
top.frames[1].onunload = top.myFunc; }, 100)
</script>

the setTimeout business is because it may be that the frameset's onload
fires when the page is read in and not after all the frames have loaded.
If you determine which it is, it would be good if you would let the group
know - and perhaps you can relax part of the above code (if it works
at all, that is).

Also, when you are doing anything with functions across frames it is a
good idea to fully qualify them (ie, appropriateWindow.functionName)

Csaba
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top