Question

I have a RESTful backend which per definition is stateless. However, I do require authentication. For this, I plan to use Basic HTTP authentication. Since that requires the username and password to be sent with every request, I want to store them clientside.

I was thinking of using the HTML5 session storage for this. The overal browser support is good enough for my application but there is one issue.

I need to catch the event when the session storage is cleared, for instance by closing the tab or clicking the logout button. Before actually clearing the session storage, I need to send the credentials to the RESTful server one last time so it can perform a clean-up operation for that user.

The issue is not so much with the logout button but more so with the tab or browser being closed...

How do I catch this event (with some Listener perhaps?), and delay it from happening until I've made a final REST call?

Was it helpful?

Solution

As far as browser and tab concern you can try following link. https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top