0

how to delete token in local storage only on browser close not on refresh I am using below approach but it is getting removed on refresh also please provide a better solution as I tried many ways it is getting failed all times

is there any alternate way please provide a solution thanks in advance

window.onunload = function () {
  localStorage.removeItem('token');
}
VAMSI AILA
  • 61
  • 1
  • 12

2 Answers2

1

You can't do it with the onunload event, but you can try to store your token in localSession instead of localStorage

0

It's impossible to tell the difference.

From the web page's point of view, closing the tab/browser and re-opening it again, and refreshing the page are the exact same actions. There's no reason for it to be different.

Lazar Ljubenović
  • 17,499
  • 8
  • 54
  • 86