19

I am testing a web app that writes cookies to subdomain.thisdomain.com and several subfolders within that. I'm looking for JavaScript that I can put into a bookmarklet that will delete all cookies under that subdomain, regardless of the folder in which they exist.

Any ideas?

2

2 Answers 2

25

Derived from my answer here:

javascript:new function(){var c=document.cookie.split(";");for(var i=0;i<c.length;i++){var e=c[i].indexOf("=");var n=e>-1?c[i].substr(0,e):c[i];document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT";}}(); return void(0);

Due to browser security issues, this will only work when executed while on a page that has access to all the cookies you want to delete.

6
  • Is there a place to put the domain name in this JavaScript? I'd like to remove cookies within my own browser for a particular domain and all subdomains. Like "www.microsoft.com" would take anything that starts with "www.microsoft.com" and remove all cookies.
    – Caveatrob
    Oct 7, 2008 at 19:38
  • 1
    Bookmarklets play inside the browser's security sandbox, so they're not allowed to edit cookies from a different domain. Oct 7, 2008 at 21:08
  • Okay. I didn't read that right. I figured anything running as a bookmarklet would have access to all browser settings.
    – Caveatrob
    Oct 9, 2008 at 14:55
  • Used the JS in a page to remove all cookies for a site. Worked great. Thx! Mar 15, 2010 at 18:39
  • 1
    It creates an anonymous function which ensures that the variables inside it are scoped to be within that function only. Feb 13, 2011 at 3:09
4

I would recommend Firecookie extension to Firebug.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.