Since , you want to refresh the whole page will be refreshed with your actual DOM code
Lets say that your button looks like:
<a href="#" id="dostuff">Click me</a>
From your sample code I am assuming that you are using Jquery
when a user clicks the button a) all the cookies are cleared b)A new cookie is set, it works as a "flag" in order to check if your page is refreshed c)The page is refreshed d) Your code checks the "flag" if is set, clears once more the cookies and redirects.
For my code I am using a jquery plugin in order to manipulate cookies easily, I will also use ocanal's function (great stuff :D )
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";
}
}
$(document).ready(function() {
var test_flag = $.cookie('flag');
//get cookie
if (test_flag == "flag_is_set") {
//if cookie is set clear all cookies once more and redirect
deleteAllCookies();
document.location = "myPage.html";
}
$("#dostuff").click(function() {
//if button is clicked
//clear all cookies
deleteAllCookies();
//set a new cookie as flag
$.cookie('flag':'flag_is_set');
//refresh page
document.location.reload();
});
});