permaculture playing cards*
The moose likes HTML, CSS and JavaScript and the fly likes not to allow closing current window.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "not to allow closing current window.." Watch "not to allow closing current window.." New topic
Author

not to allow closing current window..

Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
hi...
i have this jsp page in which i want to implement a javasrcipt that doesnot allow the user to close that page ..... is there such a java script..!
What i mean is that i want the user to click on the log out button then he will be redirected to another page but i want to restrict the user to close the window manually... how do i do that...??? and on clicking log out button i want the session to invalidate or expire ...how would i control that...!
FOR EG: view_calls.jsp has a log out button..... i want to restrict the user from closing the view_calls.jsp manually...... i have to just redirect this page by clicking the log out button and then expire the session....
Any Suggestions..!!pls help...!
thanxs...!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can not keep the user from closing the window....
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Basically, you can either open another window or submit a request to a server, using onunload handler, but that pretty much it.
Besides, what if user turns of a computer?
You should rethink your server side.
Use session timeout setting, seeeion listeners if you need to clean up something when session invalidates and so on.
Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
If i cannot close the current window .. then can u please tell me how i can re-direct to another page when the user clicks the top right button to close the window....!!!
is there a way for it ...!
Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
re-direct to another page or open another window...!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
use onunload with window.open but doing this will also cause it to open when you submit the form so you need to have a flag to check whether it is submitted or closed....
the X is not the only way to close a window either....
Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
eric..
since i'm not that familiar with java script can you please provide a code to carry out the task that you had mentioned in your previous post..!

thanxs..!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
As I always say: DO NOT RELY ON JAVASCRIPT SINCE IT CAN BE TURNED OFF. USE SERVER SIDE PROGRAMMING TO FIX YOUR BUGS! You should make your server side handle cancelling sessions with timeouts or something.....
BUT since you asked...
Basic idea:

Eric
Rekha Pande
Ranch Hand

Joined: Jan 29, 2004
Posts: 145
Thank you eric....
it worked....thanxs a lot..!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not to allow closing current window..
 
Similar Threads
How to capture close[X] function in javascript?
Doubt on closig JApplet
Customized window with no x- button
close button
login mechanism using JAVA