Jump to content

Cookies not being deleted


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...