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 Determine the close button click of Browser(IE) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Determine the close button click of Browser(IE)" Watch "Determine the close button click of Browser(IE)" New topic
Author

Determine the close button click of Browser(IE)

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,

I want to check with the help of JavaScript that 'X'(close) button of the browser is click specifically for IE browser. How can we determine the same with the help of javaScript.

Is there a way to solve the issue. Please help if having some solution for the same.

Thanks
Kushagra Bindal
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

http://faq.javaranch.com/java/CarefullyChooseOneForum


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
syed Imran
Greenhorn

Joined: Mar 20, 2007
Posts: 5
Hi....
You can do it using java script checking for browser type.Here it is,

if($.browser.msie){

//what ever you want to do specifically for ie
}

Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

First of all why do you need to do that. If you are doing something that's critical at that point you probably putting yourself to a lot of risk, specially if a user has Java Script disabled.

Second, There is no event that lets you determine the difference between a page refresh, form submission, link clicked, or browser closed. You can use onunload() and onbeforeunload() javascript events but then wont specifically triggered when the close button is clicked!

Third using browser detection is usually a Bad idea.
P.S --> if($.browser.msie){ this snippet of code assumes that you are using the Jquery Library. If you are not using a library then this snippet will not work.



Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Actually I want to remove the session on the close event of the browser.
And this is possible only when if I am able to trap the close button(X) event.
As of now I am able to trap only the mouse movement.

Thanks
Kushagra Bindal
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

The usual way is to let the session time out naturally - after all it would time out in a maximum of 20 minutes after the browser stops sending in a request. Any particular reason why you want the session to time out as soon as the browser window is closed?

You could still use the onunload() and onbeforeunload() javascript events - any reason why they don't work for what you are trying out?

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
I am maintaing a very heavy application. And number of users are also high. Thats why in general scenario it should remove the session after user click on the close button.
Thats why I am trying to implement the same.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no solution to this.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Sam Mercs wrote:You could still use the onunload() and onbeforeunload() javascript events - any reason why they don't work for what you are trying out?
I hardly think that it would be appropriate to kill the session after every page reload.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Bear Bibeault wrote:
Sam Mercs wrote:You could still use the onunload() and onbeforeunload() javascript events - any reason why they don't work for what you are trying out?
I hardly think that it would be appropriate to kill the session after every page reload.


Agreed - My mistake.
My initial impression was the unload events only fire if you move away from the domain - if you click on an external link but thats not how this works.
I guess I got to agree wih Eric - No solution - though my work around would be to reduce the session timeout. Would clean up users who have left faster.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Kushagra Bindal wrote:I am maintaing a very heavy application. And number of users are also high.

How much data do you have in the session? Maybe you could look into having less?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Thanks for all your reply.

But I am having lots of data in my session. And I am using JSF,facelets so lots of data are assign to the user session.

Also, there are so many user accessing the application at a time.
Please suggest me the way to proceed as I am still not able to solve the problem. My main aim is to detect when user click on close button. Please suggest me if is there a way to proceed.
I think there should be a way to catch the event of close button hit use by Browser internally. If it will be possible we can catch the event or any particular ID of close button, then I think it become very easy to resolve this problem.

Please help if possible.

Thanks
Kushagra Bindal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no way to just detect a close button.

What about the person typing in a URL, a browser error, alt-f4, ctrl-w, back buttons, bookmarks, etc.

There are tons of ways to leave your page and there is no mechanism built into a webpage to know the difference.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determine the close button click of Browser(IE)