1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <!DOCTYPE html> <html>
<head> <meta charset="utf-8"> <title>浏览器关闭 or 刷新</title> </head>
<body> <input type="button" onclick="disp_confirm()" value="Display a confirm box" /> <script type="text/javascript"> function disp_confirm() { localStorage.setItem("text", "111111111111111111111111") }
var time = { beginTime: 0, differTime: 0 } window.onunload = function () { time.differ = new Date().getTime() - time.begin; if (time.differ <= 3) { localStorage.clear(); } else { console.log("浏览器刷新") } } window.onbeforeunload = function () { time.begin = new Date().getTime(); }; </script> </body>
</html>
|