只在关闭浏览器时清除localStorage的方法 window.onbeforeunload = function () { if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey) { var storage = window.localStorage; //方法 storage.clear() } }