UnLoad out of body

J

Jone

Hello All,

Has anyone of you a working sample how to code an UnLoad method out of body
tag with javascript?

I have a common problem where a javascript function should be called after a
certain window is closed. I can't add javascript to window's body tag
because it's a third party code.

So a working sample in IE and Firefox would be great,

Cheers
 
E

Erwin Moller

Jone schreef:
Hello All,
Hi


Has anyone of you a working sample how to code an UnLoad method out of body
tag with javascript?

Yes, it is simple: just add the eventhandler to the body or document.

I have a common problem where a javascript function should be called after a
certain window is closed. I can't add javascript to window's body tag
because it's a third party code.

That might be more difficult.
Your 'parentdocument' (opener from the perspective of the just opened
page) cannot modify the newly opened window (since you said it is third
party, probably meaning other domain???).
So a working sample in IE and Firefox would be great,

You can however try this:
- from the opener query the newly opened window for its property 'closed'.

Here is an example.

<script type="text/javascript">
var myWinRef;
function openWin(){
myWinRef = window.open("http://www.google.com","winname");
startPolling();
}

function startPolling(){
document.forms.testform.output.value="myWinRef['closed']="+myWinRef['closed'];
window.setTimeout("startPolling();",1000);
}
</script>

<form action="" name="testform">
<input type="button" onClick="openWin();" value="Click me open new
window and try to add eventhandler">
<input type="text" name="output" size="60">
</form>

You will see the text in the field 'output' will change from false to
true when you close the new window.
This will work in FF3 and IE7. I have no clue which other browsers
support this 'closed' property... You'll have to find that out yourself.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
J

Jone

Thanks Erwin,

This approach really solved my problem!

Cheers,

"Erwin Moller"
Jone schreef:
Hello All,
Hi


Has anyone of you a working sample how to code an UnLoad method out of
body tag with javascript?

Yes, it is simple: just add the eventhandler to the body or document.

I have a common problem where a javascript function should be called
after a certain window is closed. I can't add javascript to window's body
tag because it's a third party code.

That might be more difficult.
Your 'parentdocument' (opener from the perspective of the just opened
page) cannot modify the newly opened window (since you said it is third
party, probably meaning other domain???).
So a working sample in IE and Firefox would be great,

You can however try this:
- from the opener query the newly opened window for its property 'closed'.

Here is an example.

<script type="text/javascript">
var myWinRef;
function openWin(){
myWinRef = window.open("http://www.google.com","winname");
startPolling();
}

function startPolling(){
document.forms.testform.output.value="myWinRef['closed']="+myWinRef['closed'];
window.setTimeout("startPolling();",1000); }
</script>

<form action="" name="testform">
<input type="button" onClick="openWin();" value="Click me open new window
and try to add eventhandler">
<input type="text" name="output" size="60">
</form>

You will see the text in the field 'output' will change from false to true
when you close the new window.
This will work in FF3 and IE7. I have no clue which other browsers support
this 'closed' property... You'll have to find that out yourself.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to make
it so simple that there are obviously no deficiencies, and the other way
is to make it so complicated that there are no obvious deficiencies. The
first method is far more difficult."
-- C.A.R. Hoare
 

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
474,138
Messages
2,570,802
Members
47,348
Latest member
nethues

Latest Threads

Top