• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Using onUnload

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Your mother is a hamster and your father smells of tiny ads!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic