Skip to content

Instantly share code, notes, and snippets.

@mrabbitt
Created May 31, 2014 22:12
Show Gist options
  • Save mrabbitt/47131fe10fea6cb0cb0d to your computer and use it in GitHub Desktop.
Save mrabbitt/47131fe10fea6cb0cb0d to your computer and use it in GitHub Desktop.
Delete all cookies bookmarklet
/**
* Delete all cookies for current site, using all possible domains.
*/
(function()
{
var domains = [document.location.hostname];
var hostParts = document.location.hostname.split('.');
while (hostParts.length > 2)
{
hostParts.shift();
domains.push(hostParts.join('.'));
}
var cookies = document.cookie.split(';');
for(var i = 0; i < cookies.length; i++)
{
var ep = cookies[i].indexOf('=');
var cookieName = ep > -1 ? cookies[i].substr(0, ep) : cookies[i];
document.cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
for(var j = 0; j < domains.length; j++)
{
var domain = domains[j];
document.cookie = cookieName + '=;domain=' + domain + '; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
}
alert('Deleted ' + cookies.length + ' cookies for domains: ' + domains.join(', '));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment