0

Hello,

I have two Javascript functions to set and retrieve a cookie:

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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

I can set and retrieve the cookie in Internet Explorer 9. The problem is that with Chrome, I don't know if it is not setting the cookie or not retrieving it right but I always get a NULL instead of the cookie value.

I cannot find what is the problem

Thanks in advance.

Edited by __avd: Added [code]..[/code] tags.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by MrCapuchino
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.