SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Stopping a Window from Closing
-
Feb 2, 2005, 14:11 #1
- Join Date
- Feb 2003
- Location
- Knoxville, TN
- Posts
- 531
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Stopping a Window from Closing
i have a pop-up window with a form inside... if the user is filling out the form and on purpose/on accident closes the window, i'd like for a confirmation box to pop up asking if they really want to exit before finishing and then either continue to close the window, or keep it open.
i'm assuming i need to place the script in the <body onunload="checkform();">, i'm just not sure what script to write to keep the window from closing.
-
Feb 2, 2005, 14:22 #2
-
Feb 2, 2005, 14:23 #3
- Join Date
- Nov 2004
- Location
- Right behind you, watching, always watching.
- Posts
- 5,431
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hate to be the bearer of bad tidings but there is NO 100% sure way to do this and even if you tried it will not work cross-browser .... this is one of the "age old" problems in web dev ..... most people handle this server side (IE: cleaning up sessions, removing data etc etc) ........ trying to do it client-side break almost every security rule in the book because you are attempting to manipulate their machine ........ here's some code to prove it.
Code:<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> New Document </title> </head> <body onunload="return confirm('are you sure you want to close me?');"> </body> </html>
the main problem is WHEN the onunload event fires ..... its literally AFTER the window close or they move to another page so in some browsers you actually get the confirm box AFTER the window is gone! (Neat huh)
-
Feb 2, 2005, 14:28 #4
- Join Date
- Nov 2004
- Location
- Right behind you, watching, always watching.
- Posts
- 5,431
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PS ---- this problem is EXACTLY why some of these scummy popups have NO frame at all ..... then the client CANT close them (and boy is that a pain!)
-
Feb 2, 2005, 15:56 #5
- Join Date
- Feb 2005
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try onbeforeunload and see http://www.webreference.com/dhtml/diner/beforeunload/
And for closing pop-ups.. ALT+F4?
-
Feb 2, 2005, 18:37 #6
- Join Date
- Nov 2004
- Location
- Right behind you, watching, always watching.
- Posts
- 5,431
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Now thats VERY cool encoded .... I can honestly say Ive never seen that before .... Ill have to remember that next time I need it!
-
Feb 2, 2005, 19:18 #7
- Join Date
- Aug 2004
- Location
- Wyoming, Michigan
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is quite interesting...hehe
TyeJae
= $244
Bookmarks