summaryrefslogtreecommitdiffstats
path: root/templates/javascript_refresh.inc
blob: bd6be8ac09e28532f7d94081923facd54aee9bf4 (plain)
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
35
36
37
38
39
40
41
<script language="JavaScript" type="text/javascript">
// Set refresh interval (in seconds)
var refreshinterval=<?= conf('refresh_limit'); ?>

// Display the countdown inside the status bar?
// Set "1" for yes or "0" for no
var displaycountdown=0

// main-code
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0

function starttime() {
        starttime=new Date()
        starttime=starttime.getTime()
        countdown()
}

function countdown() {
        nowtime= new Date()
        nowtime=nowtime.getTime()
        secondssinceloaded=(nowtime-starttime)/1000

reloadseconds=Math.round(refreshinterval-secondssinceloaded)
        if (refreshinterval>=secondssinceloaded) {
                var timer=setTimeout("countdown()",1000)
                if (displaycountdown=="1") {
                        window.status="Page refreshing in "+reloadseconds+
" seconds"
                }
        } else { 
                clearTimeout(timer)
                window.location.reload(true)
        }                                   
}
 
// start with page-load
window.onload=starttime
</script>