This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Clear firefox cookies on closing the window 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 "Clear firefox cookies on closing the window" Watch "Clear firefox cookies on closing the window" New topic
Author

Clear firefox cookies on closing the window

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

I want to clear all firefox cookies using javascript on window closing event. Please inform some sample script.


Thanks,
Neeraj.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Where's your code? What part are you stumped by?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hello,


I don't have the code. I am looking for some sample code, which can clear session cookies in firefox when a user closes the window instead of clicking the logout button.


Any inputs will be a great help.

Thanks
Neeraj
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

So which is your problem? Do you need code which is run upon window closing? Or do you need code which clears session cookies? Or both?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Isn't the life of the JSESSIONID cookie -1 i.e. till the browser is closed??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Thanks all for your inputs

I need to clear the session after firefox browser is closed. I was looking for a javascript event and code which will clear the session cookie when a firefox window i closed.

Thanks again.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
kindly suggest. I need to kill the user session when the firefox window closes


thanks
Neeraj.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
jsession id value is -1

tnx
neeraj.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Have you searched google?? There are tons of scripts available like this or this. And since the JSESSIONID cookie's age is -1, it should be automatically be removed when the browser window is closed??
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no way to detect if the user is closing the browser or moving to another page. So it is impossible to detect from JavaScript.

Session cookies will delete themselves when the browser is completely closed.

Eric
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
it does not happen in firefox. please test it for a normal web application


Thanks
Neeraj.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Session cookies expire when the browser is closed, permanent cookies do not. I do not need to test it. If they do not delete when ALL of the browser windows are closed, I am betting you are NOT using session cookies.

How are you setting these cookies. Show us some code.

Eric
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Transient session cookies will expire when you close ALL windows. Persistent session cookies don't expire even if you close all windows.

Try 2 following scenarios on Fire fox 3.5

Scenario A {Persistent cookies}

1.) open window A. login into yahoo/gmail accounts
2.) Close window A.
3.) Open a NEW Firefox instance B. Browse to yahoomail/gmail. You will be directly logged into your mail box.

I guess they are using persistent cookies. If you use transient cookies, it will not cache your session/request.


Scenario B {Transient cookies}

1.) create a test/find web application using transient cookies.{We did for our web application at the SiteMinder level}
2.) open window A.
3.) Login into the test application.
4.) open New Instance B. open google.com
5.) Close window A.
6.) Open Insatnce C. Browse to page after login in the test application. You will be directly logged into the application.


I am looking for a solution which can prevent the scenario B from happening in Fire Fox.


Thanks,
Neeraj.






Ashok Gawas
Greenhorn

Joined: Dec 07, 2009
Posts: 3
Hi,

This is how i delete cookies on browser closing..

cookie.setMaxAge(0);

This is very basic.. Setting the cookies age as 0 will automatically delete it when the window is closed..

Regards
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
I have already tested it. it dows not work in firefox 3.5. let me know if you have test in fire fox 3.5
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
please provide some pointers.

many thanks
neeraj.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clear firefox cookies on closing the window