setCookie() Function

How to set the cookies in javascript?
(or) setCookie function()?

Explanation

The setCookie function is used to set the cookies in javascript.

Example to set cookies, expiry date, value:


function setCookie(c_name,value,expiredays)
{
var exdate=new Date();//assigns the current date to the variable exDate
exdate.setDate(exdate.getDate()+expiredays);//sets the expiry date
document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());//sets the cookie
}
The above function sets the name of the cookies with its value along with the expiry date of the cookie.

Ask Questions

Ask Question