Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clear firefox cookies on closing the window

 
Neeraj Vij
Ranch Hand
Posts: 315
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's your code? What part are you stumped by?
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't the life of the JSESSIONID cookie -1 i.e. till the browser is closed??
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kindly suggest. I need to kill the user session when the firefox window closes


thanks
Neeraj.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsession id value is -1

tnx
neeraj.
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it does not happen in firefox. please test it for a normal web application


Thanks
Neeraj.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please provide some pointers.

many thanks
neeraj.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic