-4

I want to create a project which have a function that will refresh the browser automatically every 5 seconds . But I don't know what to do? I know that I have to put code in a Setinterval block like this:

setinterval(()=>{
// auto refresh code in here
}
  • No settimeout will only work once – Mehan alavi Jan 09 '21 at 16:59
  • 1
    `setTimeout` works once every time it is invoked. Every time your page is refreshed it the JavaScript will run again and a new timeout is invoked, so it will keep refreshing. Using `setInterval` here makes no sense, because all the existing JavaScript events/timeouts will be terminated when the page is refreshed. – Ivar Jan 09 '21 at 17:02

1 Answers1

0

As you say settimeout will only work once u need to define it simpe script (only)so everytime page load it works or better to increase intervel time some time due to network issue your page does not load properly your javascript doeasnot load also

<script type="text/javascript">
setTimeout(function(){
   window.location.reload(1);
}, 5000);
</script>
Hamza Qureshi
  • 172
  • 2
  • 20