使用 onbeforeunload 事件 onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发。 该事件可用于弹出对话框,提示用户是继续浏览页面还是离开当前页面。 //检测浏览器刷新 window.onbeforeunload = function() { //清除sessionStorage值 sessionStorage.removeItem('type') }