Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh a page after some seconds with jquery?

How to refresh a page after 5 seconds with jquery?

When user clicked on a HTML tag i want to reload correct page after 5000 seconds.

i used this code but it doesn't work

 $(".btnclose").on("click", function (e) { 
                   location.reload().delay(5000);
                   });
like image 358
motevalizadeh Avatar asked Nov 28 '22 14:11

motevalizadeh


2 Answers

You can simply use setTimeout:

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

Note that setTimeout does not guarantee exact 5 second delay. It is not very accurate.

like image 53
Yeldar Kurmangaliyev Avatar answered Dec 06 '22 13:12

Yeldar Kurmangaliyev


Like this JSFiddle:

$(".btnclose").on("click", function (e) { 
    setTimeout(function(){
        location.reload();
    }, 5000)            
});
like image 45
Amel Avatar answered Dec 06 '22 13:12

Amel