I am looking to clear the session storage only when the page is refreshed, without affecting the browser's back button functionality. I want to achieve this using AngularJS/JavaScript.
Currently, I am storing data in sessionStorage on a back button click and would like to clear this data only when the browser refresh button is clicked, without clearing it for backward navigation.
I have attempted the following:
if (performance.navigation.type == 1) {
$window.sessionStorage.clear();
// clearing the sessionstorage data
}
// However, this method clears the data after clicking the refresh button twice
if (performance.navigation.type == 0) {
$window.sessionStorage.clear();
// clearing the sessionstorage data
}
// This approach also clears the data when going back,
// I have tried using onbeforeunload and onpopstate but they are not working as expected
// Any suggestions on how to implement this correctly would be appreciated,
// Thank you in advance!
// Please note that jQuery solutions are not preferred