1

I used window.onunload and tried window.onbeforeunload but both are clearing the data on tab close as well. I want the data to remain when tab is closed and it should clear it out when the entire browser is closed. Any solution on this?

5
  • localStorage values will not clear when you closing a tab or browser. Commented Nov 3, 2015 at 11:55
  • yes... but i want to clear it, which i did but wanted to clear when windows is closed not tab.. Commented Nov 3, 2015 at 12:12
  • "LocalStorage that is closed when browser is closed" is the exact definition of SessionStorage. Commented Nov 3, 2015 at 12:30
  • 1
    i used session storage as well but the scope of storage is remain on the same page... if you open any other page on the same browser, you won't get the storage value. Commented Nov 3, 2015 at 12:58
  • You could try setting a unique identifier in a session cookie. Use that identifier as key in the localStorage. When closing the browser, the cookie is removed and so is the reference to the localStorage item :) Commented Nov 3, 2015 at 15:47

2 Answers 2

1

That's not possible. Unluckily there is no event fired when closing the entire browser (at least not in Chrome, Firefox and Internet Explorer).

You will have to find another solution to achieve what you need :(

Sign up to request clarification or add additional context in comments.

Comments

1

You should take a look at sessionStorage: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API#sessionStorage

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.