Javascript Cookie Expiration/deletion On Different Browsing Scenarios
A client requested cookie functionality where if the browser is not closed, the cookie has a 30 minute expiration, but then it needs to be removed if/when a user closes the browser
Solution 1:
I don't think it's possible, but here's a list of the window events available to you.
* onafterupdate
* onBeforeunload
* onBeforeupdate
* onBlur
* onClick
* ondblclick
* onError
* onerrorupdate
* onFocus
* onhelp
* onkeydown
* onkeypress
* onkeyup
* onLoad
* onmousedown
* onmousemove
* onmouseout
* onmouseover
* onmouseup
* onragstart
* onreadystatechange
* onresize
* onrowenter
* onrowexit
* onscroll
* onselectstart
* onUnload
Some of these may be obsolete.
Solution 2:
unload
is the standard method of detecting that the user has left your site (either closed the window/tab or navigated away)
You need to remember that if a user navigates away you cannot run code from your application anymore.
To answer your question - the code you posted is the most flexibility you will get with your scenario.
Post a Comment for "Javascript Cookie Expiration/deletion On Different Browsing Scenarios"