0

I'm looking for way to remove all my web cookies which have similar name "SID12345UID123456789" , all have SID and UID in their name ..

it can be done by jquery or pure JavaScript thanks for any advices

Update: worked base on other script i made this one it work but simple with indexOf .. i know some one can do better by regex match .. please help

var cookies = document.cookie.split(";");
for(var i=0; i < cookies.length; i++) {
    var equals = cookies[i].indexOf("="),
        name = equals > -1 ? cookies[i].substr(0, equals) : cookies[i];

    if ( name.indexOf('SID') > 0 && name.indexOf('UID') > 0 ){
        alert(name);//for test
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}
Binh Nguyen
  • 1,313
  • 3
  • 17
  • 27

1 Answers1

0

If you are creating these in your own code, you should delete the existing one before creating the new one (thus avoiding the problem).

Otherwise you can use a function like one found on this page. Run a loop that looks for a cookie with that name. If it finds it, delete it and then look again (until there are none left).

Community
  • 1
  • 1
Nick
  • 5,995
  • 12
  • 54
  • 78
  • i'm just new bie in javascript ... i have create small code here could you have look .. http://jsfiddle.net/SLcnz/ i'm still can not make it work.. – Binh Nguyen Aug 01 '12 at 10:54
  • Fantastic! If you're happy to tick my answer and/or add +1, I'd appreciate it :) – Nick Aug 01 '12 at 11:59