• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Determine the close button click of Browser(IE)

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/CarefullyChooseOneForum
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}

 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no solution to this.

Eric
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41877
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic