Jquery: Set a timeout of a page for loading

Luca picture Luca · Sep 12, 2010 · Viewed 16.6k times · Source

i would like make a script that detect if the page is full loading in 30 or else refresh the page with method (CTRL + F5) of Firefox that clear the cache of that page and refresh.. Is possibile to make? P.S: If is not possibile to make in Jquery i can use normal javascript. Thanks in advance. Kind Regards. Luca.

Answer

user372551 picture user372551 · Sep 12, 2010

plain JavaScript

var loaded = false;
var time = 30000;
window.onload = function() {
     loaded = true;
 };
setTimeout(function() {
     if(!loaded) {
         window.location.reload();
     }

},time);

jQuery

var loaded = false;
var time = 30000;
$(function() {
    $(window).load(function() {
       loaded = true;
    });
    setTimeout(function() { 
        if(!loaded) {
            window.location.reload();
        }  
    },time);
});