How to reload page every 5 seconds?

JavascriptJquery

Javascript Problem Overview


I am converting one layout to html; once I make the changes in code/html/css, every time I have to hit F5. Is there any simple javascript/jQuery solution for this? I.e. after I add the script, reload the whole page every 5 seconds (or some other specific time).

Javascript Solutions


Solution 1 - Javascript

 <meta http-equiv="refresh" content="5; URL=http://www.yourdomain.com/yoursite.html">

If it has to be in the script use setTimeout like:

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

Solution 2 - Javascript

To reload the same page you don't need the 2nd argument. You can just use:

 <meta http-equiv="refresh" content="30" />

This triggers a reload every 30 seconds.

Solution 3 - Javascript

For auto reload and clear cache after 3 second you can do it easily using javascript setInterval function. Here is simple code

$(document).ready(function() {
  setInterval(function() {
    cache_clear()
  }, 3000);
});

function cache_clear() {
  window.location.reload(true);
  // window.location.reload(); use this if you do not remove cache
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<p>Auto reload page and clear cache</p>

and you can also use meta for this

<meta http-equiv="Refresh" content="5">

Solution 4 - Javascript

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

But as development tools go, you are probably better off with a tab reloading extension.

Solution 5 - Javascript

There's an automatic refresh-on-change tool for IE. It's called ReloadIt, and is available at http://reloadit.codeplex.com . Free.

You choose a URL that you'd like to auto-reload, and specify one or more directory paths to monitor for changes. Press F12 to start monitoring.

enter image description here

After you set it, minimize it. Then edit your content files. When you save any change, the page gets reloaded. like this:

enter image description here

Simple. easy.

Solution 6 - Javascript

Answer provided by @jAndy should work but in Firefox you may face problem, window.location.reload(1); might not work, that's my personal experience.

So i would like to suggest:

setTimeout(function() { window.location=window.location;},5000);

This is tested and works fine.

Solution 7 - Javascript

A decent alternative if you're using firefox is the XRefresh plugin. It will reload your page everytime it detect the file has been modified. So rather than just refreshing every 5 seconds, it will just refresh when you hit save in your HTML editor.

Solution 8 - Javascript

Alternatively there's the application called LiveReload...

Solution 9 - Javascript

If you are developing and testing in Firefox, there's a plug-in called "ReloadEvery" is available, which allows you to reload the page at the specified intervals.

Solution 10 - Javascript

This will work on 5 sec.

5000 milliseconds = 5 seconds

Use this with target _self or what ever you want and what ever page you want including itself:

<script type="text/javascript">
function load()
{
setTimeout("window.open('http://YourPage.com', '_self');", 5000);
}
</script>
<body onload="load()"> 

Or this with automatic self and no target code with what ever page you want, including itself:

<script type="text/javascript">
function load()
{
setTimeout("location.href = 'http://YourPage.com';", 5000);
}
</script>
<body onload="load()"> 

Or this if it is the same page to reload itself only and targeted tow hat ever you want:

<script type="text/javascript">
function load()
{
setTimeout("window.open(self.location, '_self');", 5000);
}
</script>
<body onload="load()">

All 3 do similar things, just in different ways.

Solution 11 - Javascript

function reload() {
  document.location.reload();
}

setTimeout(reload, 5000);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWasim ShaikhView Question on Stackoverflow
Solution 1 - JavascriptjAndyView Answer on Stackoverflow
Solution 2 - JavascriptRid IculousView Answer on Stackoverflow
Solution 3 - JavascriptShafiqul IslamView Answer on Stackoverflow
Solution 4 - JavascriptQuentinView Answer on Stackoverflow
Solution 5 - JavascriptCheesoView Answer on Stackoverflow
Solution 6 - JavascriptNarendraSoniView Answer on Stackoverflow
Solution 7 - JavascriptDal HundalView Answer on Stackoverflow
Solution 8 - JavascriptveksenView Answer on Stackoverflow
Solution 9 - JavascriptVeeraView Answer on Stackoverflow
Solution 10 - JavascriptSeekLoadView Answer on Stackoverflow
Solution 11 - Javascriptobject-ObjectView Answer on Stackoverflow