Reputation: 1
Basically what I'm trying to do is: if you're on example.com, clear all the cookies. (using a chrome extension, I've put the background.js file in here). I can't see how this isn't working.
onload = function () {
//alert("test2");
//if we're on example.com, change the referrer header
if(currentUrl.indexOf("example.") !== -1) {
alert("it's in here");
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";
}
}
}
Upvotes: 0
Views: 79
Reputation: 2734
Change your code to the following, this way your function will be called.
onload = function () {
//alert("test2");
//if we're on example.com, change the referrer header
if(currentUrl.indexOf("example.") !== -1) {
alert("it's in here");
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";
}
}
Upvotes: 0
Reputation: 4595
You create the deleteAllCookies
function, but do not execute it. Simply call it (or do not create a function but just execute the code).
Upvotes: 1