5

I have searched up and down and have yet to find something that will allow setInterval to work in any version of Internet Explorer.

Below is the code I am using right now...

<script type="text/javascript">

$(document).ready(function () {
    $('#varRefresh').load('reload.php');

    window.setInterval("refreshVar();", 5000); //**** every 5 seconds
});

function refreshVar() {
    $('#varRefresh').load('reload.php');
}
</script>

<div id="varRefresh">
</div>

Can anyone point me in the right direction so I can get it to work in IE?

user2428118
  • 7,935
  • 4
  • 45
  • 72
unu
  • 195
  • 1
  • 3
  • 13

5 Answers5

3

The page you're trying to load may simply be cached.

You can force Internet Explorer not to cache pages as follows: Prevent caching of pages in Internet Explorer 8.

Alternatively, you may simply append a timestamp to the URL; because the URL is new to IE, it will always load the latest version.

Example:

$(document).ready(function () {
    $('#varRefresh').load('reload.php?'+new Date().getTime());

    window.setInterval(refreshVar, 5000); //**** every 5 seconds
});

function refreshVar() {
    $('#varRefresh').load('reload.php?'+new Date().getTime());
}
Community
  • 1
  • 1
user2428118
  • 7,935
  • 4
  • 45
  • 72
1

Try replacing this line:

window.setInterval("refreshVar();", 5000);   //**** every 5 seconds

with this:

window.setInterval(refreshVar, 5000);   //**** every 5 seconds

(making the first argument a function reference instead of a string)

poplitea
  • 3,585
  • 1
  • 25
  • 39
  • I tried this with no luck. It does the .load portion just fine. It just doesn't refresh every 5 seconds. – unu Nov 26 '12 at 14:05
1

Working Fiddle tested on Chrome, FireFox, Safari, Opera, Internet Explorer and android browser.

<script type="text/javascript">

$(document).ready(function () {
    $('#varRefresh').load('reload.php');
    refreshVar();
});

function refreshVar() {
    var refresh = setInterval(function(){
    $('#varRefresh').load('reload.php');
    }, 5000);
}
</script>

<div id="varRefresh">
</div>

Hope it helps!

Kareem
  • 5,068
  • 44
  • 38
0

Instead of passing the name of the function as a string literal, try passing the function as a reference like this:

window.setInterval(refreshVar, 5000);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
-2

Try to use setTimeout() instead. Look at this resource about it: http://www.w3schools.com/jsref/met_win_settimeout.asp

SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • I expected to find examples on that website `w3fools.com` meant by w3schools wrong information! – SaidbakR Oct 24 '13 at 17:51
  • 1
    You shouldn't point anyone to that site. If you change your answer, include an explanation that setTimeout will only fire once, and change that link to go to a reputable site, I'll vote your answer back up again. That link does not explicitly state that setTimeout fires only once, either. It's a bad website with bad information. – Sean Kendle Oct 24 '13 at 18:08