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 Firefox window open on unload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Firefox window open on unload" Watch "Firefox window open on unload" New topic
Author

Firefox window open on unload

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi,

I like to open a new window, when the user closed the current window.

I tried with the below code it's working in IE, But it's not working in firefox. Please assist


Reason: Am trying to open a new window. Just to say that the users session is logged out.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ugh. Don't.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Not possible in firefox ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Don't know, and I don't care: if I close a window of a website, why on earth would I want it to open *another* one? Bad user experience.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Actually am tracking user session's in a table. If suppose the user closed the window without logging out. How to track that.. Please assist me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The session will time out; use a session listener.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
You are rite !!.. My session timeout is more say for example 10 mins, But if the user closed the window and again if the user is logging the system wont allow.

Since I have table called userslist and I will insert 1 row at the time of logging and delete that while logging out or while session time out.

Could you please give me some suggestion.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why would you care if the same user logged in again?
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
I just want to track the in time and out time of all users. Thats why I am inserting 1 record while logging in. He the user closed the window. I can't track the out time. Also until the session expired the user can't re-login I mean the system won't allow. we designed like that.

I need a suggestion to trigger a event at the time of user closing the window. so that I will update the out time..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Meet Gaurav wrote: the system won't allow. we designed like that.

You designed poorly.

I need a suggestion to trigger a event at the time of user closing the window. so that I will update the out time..

As has been pointed out in these forums time and time again, you can;t reliably do this. You'll just need to rely upon the session timeout like the rest of the world.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Bear Bibeault wrote:
Meet Gaurav wrote: the system won't allow. we designed like that.

You designed poorly.

I agree: what's the reason for not allowing this? It seems pretty arbitrary, and potentially *very* annoying.

Trivial example: I work ten minutes from my apartment. I log in to your app. Without logging out, I go to work. I try to log in, and I can't. Arbitrary and capricious. If I can provide you my credentials, it shouldn't matter.

You could just set the session timeout to something very short, but that can be a little irritating too. Are you working on a website that has massive security restrictions?
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Yes, the site is designed more for security.. Is there any other option ?

My requirement is to log in time and out time of every users. If the users close the window ? How do I record out time ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Meet Gaurav wrote:Yes, the site is designed more for security

Does your design really enhance security? Really?

My requirement is to log in time and out time of every users. If the users close the window ? How do I record out time ?

As you cannot detect when a browser window is closed, you'll have to rely upon the session timeout like everyone else. This has been a recording.
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Bear Thanks for the reply..

If suppose my session time out is 1 Hr. Even if the user closed the window after 5 mins and again logged in after 10 mins,.. This shows some bad data in the DB rite.. I mean 1 sessions at the same time.

Please help. My application is designed in struts
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Meet Gaurav wrote:Please help.

What do you want help with? How many times must it be repeated that you cannot reliably detect when a browser window closes? Pleading for something that can't be done won't make it any more possible.

A better idea might be to re-evaluate your design and requirements.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Meet Gaurav wrote:If suppose my session time out is 1 Hr.

Why would you have a session timeout of 1 hour if your site is supposed to be secure?! That makes no sense.

Are you writing bank software? Government? Military? If not, what kind of information are you trying to protect?

If you cannot trust the users to be responsible and log out, you're pretty much doomed: what if the browser crashes? Or someone trips over the cord on my machine? Let alone that there's no great way to tell if the user closes the browser.

(You could use Ajax, but that would continuously refresh the session, which may or may not be what you want.)

I still believe your initial requirements have lead you down a road that dead-ends.
 
Consider Paul's rocket mass heater.
 
subject: Firefox window open on unload