mardi 2 janvier 2018

JavaScript Refresh Page after 5 Seconds on Checked Checkbox

Is there any way to refresh a webpage every 5 seconds if checkbox is checked?

For example, if the checkbox is unchecked, nothing happens, but if it's checked, then the function refresh() will make the page refresh every 5 seconds afterwards.

Here is the code I have so far, but this isn't working for some reason.

HTML:

<input type="checkbox" id="autoRefresh" onclick="if(this.checked){refresh()}" checked>

JS:

function refresh() {
         setTimeout(function () { location.reload() }, 5000);
    }




Aucun commentaire:

Enregistrer un commentaire