Is there any possible way to return the expiration time of a pefeied cookie by JavaScript?

What I read so far:
1) Create another cookie to hold the expire time.
-I don't want to use that because i do not intend to do it, simple enough.

2) I don't really understand this area but I read that there is a way to play with the header, and maybe get the expire time.
By using the XMLHttpRequest.

Maybe you have some ideas?

Recommended Answers

All 3 Replies

If you have a server-side script that sets cookie headers, you can get the expiration date of the cookies that are set on that page, with an XMLHttpRequest, but you have to actually 'execute' that page. Otherwise, nothing I can think of.

Thank you,
So can I do what you wrote but create the cookie with js and retrieve the data via php?
2) When I alert document.cookie offline it won't work, is this because the cookie needs a domain/ path of the http protocol?
--Can js cookie functions work offline?--

Thanks in advance!

Nope. A browser does not send php info on the expiration date. Cookies are not meant to work offline, but they do in every browser except Chrome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.