• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to close the window after clicking on logout link in java  RSS feed

 
sv krishnaveni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to close the window after clicking on logout button in servlets
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kittu" please check your private messages.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Browsers will only let you close windows that you opened.
Even if you could (which you can't), it would be rude of your app to close someone's browser.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16007
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you can do is make the servlet send a page with some JavaScript to the client. You can use:

window.close()

in JavaScript to close the user's broswer. Note however that many browsers do not allow JavaScript to close the browser immediately. The browser will most likely display a popup saying something like "A script on this page wants to close the browser. Do you want to allow that?". For security reasons, it's not possible to bypass that warning from your JavaScript.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
What you can do is make the servlet send a page with some JavaScript to the client. You can use:

window.close()

in JavaScript to close the user's broswer. Note however that many browsers do not allow JavaScript to close the browser immediately. The browser will most likely display a popup saying something like "A script on this page wants to close the browser. Do you want to allow that?". For security reasons, it's not possible to bypass that warning from your JavaScript.


I just tried the following on both MSIE and FF.
In both cases it was ignored, no messages, no warnings, just... nothing.

 
Norm Radder
Ranch Foreman
Posts: 2222
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I ran the above HTML in Firefox 3.0 I got following in the Error console:

Warning: Scripts may not close windows that were not opened by script.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the bottom line here is that there is no reliable way to close the user's browser window from within a webapp and, if there was, it is a bad thing to do. As an end user, I expect to be able to use the back button to return to previous pages or applications. And, since all major browsers support tabs now, I would be particularly upset if an application or page in one tab were to close the entire window without my consent.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kittu, welcome to Javaranch,
looks like your question is already answered by the above posts.
I would just like to make you aware that your name does not follow the Javaranch naming policy please change it here.
Also please follow the Ask good questions link below.
Thanks.
[ July 01, 2008: Message edited by: Amit Ghorpade ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!