javascript - How to Delete all Cookies on my site except for one -
i'm using following function clear cookies, works. clearing out phpsessid
far can tell. want retain 1 cookie alone.
i added line: if (name == "phpsessid") {...
...to try , catch, , skip, altering cookie names phpsessid
, doesn't catch reason.
is there clear reason why it's not catching, or there better way achieve clearing cookies except "phpsessid
"?
the function:
function clearcookies() { var cookies = document.cookie.split(";"); for(var i=0; < cookies.length; i++) { var equals = cookies[i].indexof("="); var name = equals > -1 ? cookies[i].substr(0, equals) : cookies[i]; if (name == "phpsessid") { alert("yes"); }else{ document.cookie = name + "=;expires=thu, 01 jan 1970 00:00:00 gmt"; alert(name); } } }
hi found answer using devtool's console log instead of cookie viewer. there's space in front of phpsessid when it's set reason. " phpsessid" works.
solution here: output in console log instead of alert.
Comments
Post a Comment