JQuery Redirect to URL after specified time

前端 未结 9 932
感动是毒
感动是毒 2020-12-07 17:20

Is there a way to use JQuery to redirect to a specific URL after a give time period?

相关标签:
9条回答
  • 2020-12-07 18:06

    Yes, the solution is to use setTimeout, like this:

    var delay = 10000;
    var url = "https://stackoverflow.com";
    var timeoutID = setTimeout(function() {
        window.location.href = url;
    }, delay);
    

    note that the result was stored into timeoutID. If, for whatever reason you need to cancel the order, you just need to call

    clearTimeout(timeoutID);
    
    0 讨论(0)
  • 2020-12-07 18:09

    Use setTimeout function with either of the following

    // simulates similar behavior as an HTTP redirect
    window.location.replace("http://www.google.com");
    
    // simulates similar behavior as clicking on a link
    window.location.href = "http://www.google.com";
    
    setTimeout(function(){
       window.location.replace("http://www.google.com");
    }, 1000) 
    

    source: https://www.sitepoint.com/jquery-redirect-web-page/

    0 讨论(0)
  • 2020-12-07 18:10

    just use:

    setTimeout("window.location.href='yoururl';",4000);
    

    ..where the '4000' is m.second

    0 讨论(0)
提交回复
热议问题