File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to stop browser pange closing without showing confirm dialog box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to stop browser pange closing without showing confirm dialog box" Watch "How to stop browser pange closing without showing confirm dialog box" New topic
Author

How to stop browser pange closing without showing confirm dialog box

Venkata Ramana
Greenhorn

Joined: Feb 14, 2002
Posts: 17
Hi
I need to stop my browser page closing when user clicks on 'X' symbol located at top right carner.
i used the following html and javascipt code.

The above code is working fine.
When the user clicks on 'X' symbol, it will promt in confirm dialog box.If user clicks on 'ok' the browser window will close. if user clicks on 'cancel' the browser don't close.
I don't want to display the confirm dialog box, and i want my browser window to be opened.
(i.e. actually i want to cancel the event which fires when 'X' button is clicked.)
ramana
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

i dont think you can thank god!
although i have been to sites that popped up windows faster than i could close them ive never been unable to close one. you can make them really big so the X is off the screen, but it can still be closed by right clicking on it in the task bar.


SCJP
Visit my download page
Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
You can't STOP them from closing the window but in I.E. 5.5 there is a confirm window of some sort the works a little like an alert. It pops up a mini dialog window with OK and Cancel buttons on the bottom. Here is where you can ask them if they really want to close the window.
If u are writing some kind of webapp you could simulate a call to logout code on the server with the on close method if the user clicks OK.
You can also save the user's session data, at that point, if you need to.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

he knows about the confirm dialog box. thats what hes trying to avoid. why do you want to be so mean to your visitors/users anyway?
by the way, you do realize that onbeforeunload only works in IE dont you?
[ April 18, 2002: Message edited by: Randall Twede ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can do an onunload pop up of the same page they were on......But most people will close them before they will open.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to stop browser pange closing without showing confirm dialog box
 
Similar Threads
need to differentiate between the window closing an window refreshing
catching page change or browser close
Using onbeforeunload event of Javascript
How to stop browser window closing
session