我只想在页面刷新时清除会话存储,而不是在浏览器后退按钮单击或向前单击时清除会话存储想使用 angularjs/javascript 实现它
我在单击后退按钮时将数据保存在会话存储中,所以我只想在单击浏览器刷新按钮时清除相同的数据,但它不应该清除后退
我努力了
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
原文由 vijay ram 发布,翻译遵循 CC BY-SA 4.0 许可协议
是的,您可以在 Windows 加载时实现此目的,然后清除会话存储或删除密钥