jsブラウザクローズor更新


jsブラウザクローズor更新

<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,//  onbeforeunload     
			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>