setCookie and getCookie - cross browser help

function setCookie(c_name,value)
{
	document.cookie=c_name+ "=" +escape(value)+"; expires="+365*24*60*60*1000;
}
		
function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

this no work in ie9 i guess and ie8 and below… well can you help with cross browser code?

Hi there,

I suggest you read this: http://www.quirksmode.org/js/cookies.html

It won’t work anywhere. The expiry date format is incorrect and your code has no way of setting the expiry date/duration. If this is intended only to set session cookies, remove the expiry parameter.

but works only in ie9 etc ie not… as the below from
http://www.quirksmode.org/js/cookies.html
are cross platform???

function createCookie(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 readCookie(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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

I’m pretty sure that the Quirksmode script will work in all major browsers, so yes.