Is there any way to retrieve the time remaining for a cookie to expire in javascript or jquery?
Is there any way to retrieve the time remaining for a cookie to expire in javascript or jquery?
You simply can not get this kind of information with JavaScript because it is not available in document.cookie
.
However, since there is a problem for everything, if you are setting this cookie, you can create a second to support it, storing the creation dates in it.
Already have an accepted answer and in fact it is correct because you can not read this information.
I leave one more response with an idea in case Cookie is created by you. You can write the end date in Cookie itself.
var data = new Date();
data.setSeconds(data.getSeconds() + 10); // Cookie com 10 segundos de vida
data = new Date(data);
$.cookie('meu_cookie', data, {
expires: data
});
Example: link
Note that Cookies can be changed by the user, so they can not be trusted.