1var getCookies = function(){
2 var pairs = document.cookie.split(";");
3 var cookies = {};
4 for (var i=0; i<pairs.length; i++){
5 var pair = pairs[i].split("=");
6 cookies[(pair[0]+'').trim()] = unescape(pair.slice(1).join('='));
7 }
8 return cookies;
9}
10
11var myCookies = getCookies();
12console.log(myCookies);
1function deleteAllCookies() {
2 var cookies = document.cookie.split(";");
3
4 for (var i = 0; i < cookies.length; i++) {
5 var cookie = cookies[i];
6 var eqPos = cookie.indexOf("=");
7 var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
8 document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
9 }
10}
11
12deleteAllCookies();
1function deleteCookie(name) {
2 document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
3}
1document.cookie.split(";")
2 .forEach(function(c) {
3 document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); });
4
1function clearCookies(wildcardDomain=false, primaryDomain=true, path=null){
2 pathSegment= path ? '; path=' + path : ''
3 expSegment="=;expires=Thu, 01 Jan 1970 00:00:00 GMT"
4 document.cookie.split(';').forEach(
5 function(c) {
6 primaryDomain && (document.cookie = c.replace(/^ +/, "").replace(/=.*/, expSegment + pathSegment))
7 wildcardDomain && (document.cookie = c.replace(/^ +/, "").replace(/=.*/, expSegment + pathSegment + '; domain=' + document.domain))
8 }
9 )
10}