View difference between Paste ID: b3BFf6vE and Wc1dACSR
SHOW: | | - or go back to the newest paste.
1
<!doctype html>
2
<html lang="en">
3
<head>
4
	<meta charset="UTF-8">
5
	<title>Auto refresh</title>
6
</head>
7
<body>
8
	<label><input type="checkbox" name="chk_refresh" onchange="swith_refresh();" id="chk_refresh">Auto refresh</label>
9
	<div>
10
		Random number (for reload test): <span id="span_rnd"></span>
11
	</div>
12
13
	<script type="text/javascript">
14
		chk_refresh.checked = ( localStorage.is_refresh == 1 );
15
		span_rnd.innerHTML = Math.random();
16
17
		function swith_refresh(){
18
			if ( chk_refresh.checked ){
19
				localStorage.is_refresh = 1;
20
				refresh_after_timeout();
21
			} else {
22
				localStorage.is_refresh = 0;
23
			}
24
		}
25
26
		function refresh_after_timeout(){
27
			setTimeout( function(){
28
				location.reload();
29
			}, 2000 );
30
		}
31
32
		if ( localStorage.is_refresh == 1 ){
33
			refresh_after_timeout();
34
		}
35
36
	</script>
37
</body>
38
</html>