Good morning people
I am attempting to clear all of my cookies, some of which are set on a server and some of which are browser cookies.
I have tried using document.cookie = "" however this did not satisfy my needs so I wrote some Javascript code, which can be seen below
The pauseClearAllCookies function is called onload.
<script type="text/javascript">
//var cookie_names = new Array("__utma", "__utmb", "__utmc", "__utmz", "mortgage", "track_source","currency","selenium_testing","visit_secure_token", "rdb_history", "_csuid", "search", "finance", "searchhistory");
function pauseClearAllCookies(){
Set_Cookie("selenium_testing","1");
drawTable();
setTimeout("checkCookies();",1000);
document.getElementById('msg').innerHTML = "Gathering Cookies....";
}
var cookie_counter = 0;
var cookieList;
function checkCookies(){
if(document.cookie.indexOf(";") != -1){
cookieList = document.cookie.split(";");
}else{
cookieList = [document.cookie];
}
setTimeout("clearAllCookies();",1000);
}
function clearAllCookies(){
document.getElementById('msg').innerHTML = "Deleting Cookies....";
if(cookie_counter < cookieList.length ){
var cookieName = "";
if(cookieList[cookie_counter].indexOf("=") != -1){
cookieName = cookieList[cookie_counter].split("=")[0];
}else{
cookieName = cookieList[cookie_counter];
}
document.getElementById('msg').innerHTML = "Deleting Cookie: "+cookieName;
// clear js cookies
Delete_Cookie(cookieName, '/', document.domain);
Delete_Cookie(cookieName, '/', '.www.abc.co.uk');
Delete_Cookie(cookieName, '/', 'www.abc.co.uk');
Delete_Cookie(cookieName, '/', '.abc.co.uk');
// clear server cookies
Delete_Cookie(cookieName, '/', '');
// increment counter
cookie_counter++;
drawTable();
//recall the function
setTimeout("clearAllCookies();",800);
}else{
Set_Cookie("selenium_testing","1");
}
}
function drawTable() {
var allcookies = document.cookie.split(";");
document.getElementById('heading').innerHTML = allcookies.length + " cookie found";
var table_html = "<table class='data'>";
for(var i=0; i < allcookies.length; i++){
var cookie = allcookies[i].split("=");
table_html += "<tr>";
table_html += "<td>"+(i+1)+"</td>";
table_html += "<td>" + cookie[0] + "</td>";
table_html += "<td>" + cookie[1] + "</td>";
table_html += "<tr>";
}
table_html += "</table>";
document.getElementById('table').innerHTML = table_html;
}
</script>
The problem is that every time I run this code one cookie is left behind, it is looped through however not deleted and its ALWAYS item number one in the Array. Any help in sorting this issues really would be very much appreciated
Thank you all for your time
cameron