Search code examples
jqueryrefreshdelayreload

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

Solution

  • 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.