Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Determine the close button click of Browser(IE)

 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
syed Imran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no solution to this.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic