Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在关闭选项卡时清除本地存储。如果我使用$(window).unload,它也会在页面刷新时清除存储。有没有办法只有在标签关闭时才能做到这一点?
$(window).unload
如果您只想使用此事件来清除 localStorage,则可以考虑改用 sessionStorage。不同的是,当标签页或窗口关闭时,浏览器会处理清除数据(刷新时数据仍会保留)。