• 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

window.onunload not called on closing the browser

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Google Chrome.

Following code is in my Jsp


On closing the window, this code is not called up (alert is not executed)
While i did the same check using firefox with little change in code as "window.screenX" and "window.screenY", the code is called up only when i close the tab , and not the whole browser
What is the problem?
(I have also checked similar topics in this forum, but, couldn't find the solution)
 
author
Posts: 297
5
Android Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a long discussion of the issues with unload in the blog post WebKit Page Cache II – The unload Event, for more modern browsers try pageshow and pagehide.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the page unloads you have no control over it. You can not redirect to another page when it is exiting. Session end event on the server should end the session.

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a requirement in my application, where only one user with a particular username can log in at a time. Also, if he is logged in, the status in db changes to LOGGED IN. When he logs out, status chnages to LOGGED OUT.
Suppose, i set the time out to 15mins, or session inactiave to 5mins. The user accidently closes the browser. Then, status remains LOGGED IN, unless and until, that time period of 5mins/15mins is over.
That's the reason why, i need to invalidate the session as soon as browser closes (or PC shuts down)
 
Sheriff
Posts: 67746
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
Requirements that cannot be met need to be changed.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wish i could. But, all depends on my seniors. I was just said to implement this
 
Bear Bibeault
Sheriff
Posts: 67746
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
Well, as there is no way for this to be accomplished, you have a problem. You can either:
  • Let whoever is setting the requirement know that the session timeout is the only way to know if a browser has been adandoned
  • Or, continue to waste time trying to find a way to do this when it cannot be accomplished.

  • Bottom line: you can not get any reliable indication that a browser has been abandoned, or that a PC has been shut down, or has crashed. In these cases, you need to rely upon the session timeout.
     
    Kunal Lakhani
    Ranch Hand
    Posts: 622
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Bear,Eric Pascarello,Rob Crowther for your replies
     
    Kunal Lakhani
    Ranch Hand
    Posts: 622
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hello
    I have got another situation, which is causing problem.
    My servlet class has following lines in the beginning :

    Suppose the user closes the browser, and session still is active (some mins remaining to make it inactive)
    If some user, without login in, types any url specified in the web.xml, which calls any servlet. Then, that will change the db details, since it will satisfy the condition stated above in if block
    That's the reason why i want to invalidate the session on closing of browser
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    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
    Again, it does not matter why you want to do it. It is the responsibility of the user of the application to log out of the application, and for you to set the session timeout to an appropriate value.

    P.S. Why the check for isNew()? It's superfluous.
     
    Kunal Lakhani
    Ranch Hand
    Posts: 622
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    P.S. Why the check for isNew()? It's superfluous.



    Will username == null alone do?
     
    Rancher
    Posts: 2759
    32
    Eclipse IDE Spring Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmm if user closes the browser, and another user logs in, the second user should get a different http session
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    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

    Kunal Lakhani wrote:

    P.S. Why the check for isNew()? It's superfluous.



    Will username == null alone do?



    Think about it. Will there ever be a new session with a username in it?
     
    Kunal Lakhani
    Ranch Hand
    Posts: 622
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Think about it. Will there ever be a new session with a username in it?



    No. Not at all.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    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
    Right. So why check for it?
     
    Kunal Lakhani
    Ranch Hand
    Posts: 622
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Right

    Thanks Bear Bibeault, Jayesh A Lalwani, Eric Pascarello, Rob Crowther
     
    reply
      Bookmark Topic Watch Topic
    • New Topic