javascript - How to make sure a cookie will expire? -


i feel question simple. i'm using js, , have cookie set expire in 7 days. how can test cookie expire in 7 days? help.

it not possible expiration date of cookie through javascript key-value pairs available through document.cookie.

all can check if cookie exists using following function:

function getcookie(name) { //returns cookie value or null     var dc = document.cookie;     var prefix = name + "=";     var begin = dc.indexof("; " + prefix);     if (begin == -1) {         begin = dc.indexof(prefix);         if (begin != 0) return null;     }     else     {         begin += 2;         var end = document.cookie.indexof(";", begin);         if (end == -1) {         end = dc.length;         }     }     return decodeuri(dc.substring(begin + prefix.length, end)); }  

Comments