Aadi
Aadi

Reputation: 7109

Javascript Cookie

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....

Upvotes: 8

Views: 12180

Answers (2)

lugte098
lugte098

Reputation: 2309

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

setCookie('gs_cookie','firstme');

Upvotes: 8

Pekka
Pekka

Reputation: 449803

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

Upvotes: 4

Related Questions