8

How can i create a cookie by using javascript just for end of the browser session(ie,upto closing of current browser).My script is like follows;

function setCookie(c_name,c_value,c_expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+c_expiredays);
    document.cookie=c_name+ "=" +escape(c_value)+
    ((c_expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

setCookie('gs_cookie','firstme',1600000);

How much value i need to pass instead of 1600000. Please help....

Blazemonger
  • 86,267
  • 25
  • 136
  • 177
Aadi
  • 6,633
  • 27
  • 94
  • 145

2 Answers2

8

If you dont set any expire time, the cookie will be deleted upon closing of the browser:

setCookie('gs_cookie','firstme');
lugte098
  • 2,143
  • 5
  • 20
  • 28
4

Setting c_expiredays to 0 (without quotes) should do the trick.

Pekka
  • 431,103
  • 135
  • 960
  • 1,075