wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Using onUnload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using onUnload" Watch "Using onUnload" New topic
Author

Using onUnload

shaji bala
Greenhorn

Joined: Nov 02, 2000
Posts: 2
Hi,
I have a popup window which contains a form which the user can to set/update his preferences(This has a submit button). Now if he tries to close the popup window without submitting the form, I have a confirm box which asks him whether he wants to close the window. So the popup window should remain open until the user confirms it to be closed. I thought "onUnload" property will do, but that property seems to be used only after unloading of the window, not just prior to it. It is too late by then.
Someone sugested "onbeforeUnload" but it works in IE not in netscape. Can someone help me out?
Thaks,
Shaji B
manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
well one solution could be to remove the tool bar from the window and provide a button to close the window...so that u can have a confirm popup when the button is clicked (onClick()) and then when confirm returns true u can say self.close() (actually self.close() ) should pop up a dialog box on its own...anyway i hope you get the idea...thats how most popups are they are without the tool bar so a user cannot click to close it
manav
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
manav solution is nice, but even without the toolbars someone can hit the "X" in the corner and close the window. I would go with manav solution at first until you can figure something else out. I never had to try and do this, and I would have went with onUnload also.
What you may be able to do is have a javascript call in the main window that runs the code. Then you can set a flag on the main page with "false" and if they fill out the form, change the flag to "true". Then when they close the window, have an onUnload call that runs the function on the main page, if it is false then open up the dialog box. If they hit "yes" (being they do want to fill out the form) then just open the window back up.
To make it look better I would use the IE call onbeforeUnload and then have and onLoad call also like above. Just before you run it, check to see what browser they are running and don't run the function for IE users, since you were able to run it for IE on the onbeforeUnload call. Not the prettiest solution but still does what you want it to do.
Other than that, I can't think of any function in Netscape like the IE function.
One more note, as to manav reference that self.close() will cause an alert box, that is only true if you are trying to close the parent window, not a child window. Child window's can be closed anytime, by the parent or the child.
Hope that helps,
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using onUnload
 
Similar Threads
How to capture popup window close event.
Closing a popup window, when parent window is closed
Popup form, parent form
How to refresh the main window once we close the popup
Window Focus