You need to sign in to do that
Don't have an account?

Cookie deletion
Hello!
I'm triing to delete a cookie after a user log out but well, I don't find how to do that. Of course, the cookie is deleted when the browser is closed but if the user log again (and do not close the browser), the cookie is kept, which is not wished.
An alternative would be to store the session Id in the cookie but it appears that the session Id is different for each page meaning it's not reliable (I thought that the sessionId is the same for the whole "Session" but well, it is not).
Finally, what I'm triing to do: a teaser should be showed on the first page when the user log in. If the user clicks on a button, this teaser is hidden for the whole session. But if the user log out and log in again, this teaser should be showed again! It works as intended if the user closes its browser... but only on this condition unfortunately :(
any idea how to solve that ?
Thank you!!
Hi,
Just make new cookie with the same name , it's should clear your cookie .
here is some code that will make your job when user is logged out
If you handle cookies on SF:
// create a new cookie with name 'MYCookie', an initial value of Name at the page,
// path 'null', maxAge '-1', and isSecure 'false'.
Cookie myCookies=new Cookie('MYCookie','',null,-1,true);
If you handle cookies on JS:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/ ";
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
hope this helps.
Thank you for your answer but well, how do you know when the user log out ? It's indeed rather my problem. Because this "log out" is done automatically by Salesforce and I don't do anything.
You can't take over the "log out" of SF but you can attach a session ID for each cookie, that will helps you to handle session cookie's
On the other hand you can handle this JS
you can delete the cookies when the page is redirect
Add in body Tag:
and this js function:
It's no matter where the user will logged out the function will run.
and about the session there is a session for the logging
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_login_loginresult.htm#topic-title
see under sessionId function