By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,608 Members | 3,801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,608 IT Pros & Developers. It's quick & easy.

UnLoad out of body

P: n/a
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
Oct 23 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
>
Cheers

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
Oct 24 '08 #2

P: n/a
Thanks Erwin,

This approach really solved my problem!

Cheers,

"Erwin Moller"
<Si******************************************@spam yourself.comwrote in
message news:49*********************@news.xs4all.nl...
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.
>>
Cheers

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

Oct 25 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.