Skip to content

Instantly share code, notes, and snippets.

@normanzb
Created April 21, 2015 14:39
Show Gist options
  • Save normanzb/ee8ffede036a6c63a655 to your computer and use it in GitHub Desktop.
Save normanzb/ee8ffede036a6c63a655 to your computer and use it in GitHub Desktop.
new cookie clearing script
<script>
(function() {
function setCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function removeCookie(name) {
setCookie(name, "", -1);
}
function getCookieNames() {
var ret = [];
var cookieStrings = document.cookie.split(';');
var currentCookieString = '';
for(var i = 0; i < cookieStrings.length; i++) {
currentCookieString = cookieStrings[i];
ret.push(currentCookieString.substring(0, currentCookieString.indexOf('=')));
}
return ret;
}
function removeAllQTagCookies() {
var cookieNames = getCookieNames();
var cookieName;
for(var l = cookieNames.length; l--;) {
cookieName = cookieNames[l];
if (cookieName.indexOf('qtag_') >= 0) {
removeCookie(cookieName);
}
}
}
removeAllQTagCookies();
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment