Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setInterval & Internet Explorer

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?

like image 909
unu Avatar asked Oct 22 '22 00:10

unu


2 Answers

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());
}
like image 166
user2428118 Avatar answered Nov 03 '22 22:11

user2428118


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)

like image 26
poplitea Avatar answered Nov 03 '22 22:11

poplitea