我希望只有在页面刷新时才清除会话存储,但不会在浏览器的"后退"或"前进"按钮点击时清除。我想使用angularjs/javascript实现这一点。
我正在点击"后退"按钮时保存数据到sessionstorage中,因此我只想在单击浏览器刷新按钮时清除相同的数据,但是它不应该在后退时清除。
我已经尝试过:
if (performance.navigation.type == 1) {
$window.sessionStorage.clear();
// clearing the sessionstorage data
}
// but this one is clearing after clicking 2 times on refresh button
if (performance.navigation.type == 0) {
$window.sessionStorage.clear();
// clearing the sessionstorage data
}
// this one is clearing for back button as well ,
// tried onbeforeunload, onpopstate as well its not working its clearing for back button too
// please let me know how to implement this one, thanks in advance
// no jquery please