javascript set cookie 1

javascript set cookie

function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}

deleteAllCookies();

Here is what the above code is Doing:
1. It’s creating a function called deleteAllCookies()
2. It’s getting all the cookies from the document.cookie property
3. It’s looping through all the cookies and deleting them one by one
4. It’s calling the deleteAllCookies() function

Similar Posts