onunload without body tag reference?

B

Brian Vallelunga

I'm working on an asp.net site and am trying to implement a popup help
window. I want the window to close when the user advances to the next page
in our application. The thing is, I'm doing this on a component basis and I
don't have access to the body tag from within my help component, so I can't
add the onunload tag. Is there some other way of achieving what I want? Can
I add an eventhandler to the body tag through javascript?

Thanks,

Brian
 
G

Grant Wagner

Brian said:
I'm working on an asp.net site and am trying to implement a popup help
window. I want the window to close when the user advances to the next page
in our application. The thing is, I'm doing this on a component basis and I
don't have access to the body tag from within my help component, so I can't
add the onunload tag. Is there some other way of achieving what I want? Can
I add an eventhandler to the body tag through javascript?

Thanks,

Brian

<script type="text/javascript">
function myUnloadHandler() {
// do something
}
window.onunload = myUnloadHandler;
</script>

The problem of course is that when the unload event fires, I'm not sure if the
function is still in scope on the page. What you may need to do is put the
unload event handler function in the opener, then invoke it from the popup:

<script type="text/javascript">
function popupUnloadHandler() {
if (window.opener && window.opener.unloadHandler) {
window.opener.unloadHandler();
}
}
window.onunload = popupUnloadHandler;
</script>

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
B

Brian Vallelunga

Thanks for the suggestions. I actually found a way to do this with asp.net.
Essentially, I am able to call a script from onsubmit. So all I do is define
a script, and then register it with the RegisterOnSubmitStatement() method.
Thanks for the help though.

Brian
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top