Jump to content

Cookies not being deleted


Shinori

Recommended Posts

Dear forumusers,

 

I'm currently having trouble with deleting my browsercookies. Specifically speaking im trying to delete the cookies of the website the user is currently on.

Here are my JS functions + the proof for existing cookies.

function setCookie(cname, cvalue, days) 
{
	var dt, expires;
	dt = new Date();
	dt.setTime(dt.getTime()+(days*24*60*60*1000));
	expires = "; expires="+dt.toGMTString();
	document.cookie = cname+"="+cvalue+expires+';';
}
function delCookie(name)
{
	document.cookie = name + '= ; expires = Thu, 01 Jan 1970 00:00:00 GMT';
}
function logout()
{
	var cookie = getCookie("member");
	if(typeof cookie != "undefined" || typeof cookie != null || cookie.length > 0)
	{
		delCookie("member");
		window.location.reload();
	}
	else
	{
		alert("Beim Logout ist etwas schief gelaufen!");
		window.location.reload();
	}
}

 

Apparently my browsers language isn't english. Sorry for that. Basically it says that the cookies name is "member", that is has content and expires in 1 day.

 

image.png.32f2c102b063d3aaf5c43fd7008e910b.png

 

I call the "logout"-function via onclick event in visible DOM. The functions gets called successfully. The cookie existence of "member" is then successfully validated and delcookie() is called. 
The windows gets reloaded as logout() is suppose to do.

Eventually the cookie is NOT being deleted. Any ideas whats going wrong her?

 

Thanks in advance! Sorry for my bad english :S

Edited by Shinori
Link to comment
Share on other sites

13 minutes ago, justsomeguy said:

Try this instead:

 


document.cookie = name+'=; Max-Age=-99999999;';

 

Didn't change anything. The cookie still hasn't been deleted.

13 minutes ago, dsonesuk said:

Just one question, where's getcookie() function?

Here it is: 

function getCookie(cname) 
{
	var name = cname + "=";
	var decodedCookie = decodeURIComponent(document.cookie);
	var ca = decodedCookie.split(';');
	for(var i = 0; i < ca.length; i++) 
	{
		var c = ca[i];
		while (c.charAt(0) == ' ') 
		{
		  c = c.substring(1);
		}
		if (c.indexOf(name) == 0) 
		{
		  return c.substring(name.length, c.length);
		}
	}
  return "";
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...