Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i have js function which set cookie as below

JavaScript
function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setDate(date.getDate() + days);
        var c_value = escape(value) + ((date == null) ? "" : "; expires=" + date.toUTCString());
    }
    else
        var expires = ""; document.cookie = name + "=" + value + expires + "; path=/";
} 


i want now to set cookie to be expired after 15 minute

any help

Thanks
Posted

1 solution

Follow this logic:
JavaScript
//original timestamp
var d1 = new Date (),
// new timestamp
d2 = new Date ( d1 );
d2.setMinutes ( d2.getMinutes() + 15 );

Of course, you don't need two objects, use this as needed.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900