I am quite new to Javascript. I am trying to implement a button that controls whether a page is refreshing or not. However, it doesnt work (clicking on the button triggers some actions like alert etc, but doesnt change the label button and doesnt stop refreshing the page).
Can you tell me where I went wrong, please? Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Message log</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body onload="JavaScript:timedRefresh(5000);">
<button id="bRefresh" onclick="refreshMode()">Stop refreshing</button>
some content...
</body>
</html>
<script type="text/JavaScript">
<!--
var refresh = 1;
function timedRefresh(timeoutPeriod) {
if(refresh == 1) {
setTimeout("location.reload(true);",timeoutPeriod);
}
}
function refreshMode() {
if(refresh == 1) {
var refresh = 2;
document.getElementById("bRefresh").value="Start refreshing";
} else {
var refresh = 1;
document.getElementById("bRefresh").value="Stop refreshing";
}
};
// -->
</script>