开发者

Jquery: Set a timeout of a page for loading

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 javascrip开发者_如何学运维t. Thanks in advance. Kind Regards. Luca.


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);
});


You can write this in your html head:

<meta id="meta-refresh" http-equiv="refresh" content="30; URL=(your url)">

It refreshes the page after 30 seconds. In your jQuery part there could be something like this:

$(window).load(function() {
  $("#meta-refresh").remove();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜