I have tried to program a little self-updating iFrame that can be turned on and off. I have run into a few problems though. I managed to get the buttons working quite easily, and made them able to change my exe value which should be the trigger for the actual reloading process.
Now, this seemed easy in my head but I have tried the ideas that I had, and I am not too familiar with JavaScript. - The sleep function is taken elsewhere so that I can reload the page, sleep for x amount of milliseconds before it reloads again (while the start button is the active one).
The problem is to get the frame to actually update, and do it according to the exe value. I tried with a while statement, but even with my sleeper it just saw it as an infinite loop and froze, leaving me unable to control it with buttons. I tried making it a function with an if-statement to see if Javascript somehow kept calling the code, that wasn't the case... So now I am a bit confused on how to solve this problem and make the page actually reload every time.
<!DOCTYPE html>
<html>
<head>
<title>Updater</title>
</head>
<body>
<script language="javascript">
var exe = 1;
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function reload() {
document.getElementById('update_frame').contentWindow.location.reload(true);
sleep();
}
if (exe == 1) {
windows.setInterval(reload(), ms);
}
function start() {
exe = 1;
}
function stop() {
exe = 0;
}
</script>
<IFRAME name="update_frame" src="http://www.google.com" width="300" height="200" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></IFRAME>
<br />
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
</body>
</html>
Tips to solving this puzzle would be appriciated! Thanks in advance :D