Delay automatic url redirect with jquery?

后端 未结 4 1591
自闭症患者
自闭症患者 2020-12-28 13:25

I need a transition page that will display for 2 seconds before automatically redirecting to the home page. How do I do this? I can\'t seem to get delay to work for me.

相关标签:
4条回答
  • 2020-12-28 13:43
    setTimeout(function(){ window.location = "/NewPage.aspx"; }, 2000);
    
    0 讨论(0)
  • 2020-12-28 13:50

    You could use jQuery Timer. Here is the code (also found in this article):

    // This will hold our timer
    var myTimer = {};
      // delay 2 seconds
      myTimer = $.timer(2000, function() {
    
      //redirect to home page
      window.location = "/RedirectTimer/Home.aspx";
    });
    
    0 讨论(0)
  • 2020-12-28 13:53

    You can just use setTimeout() directly, like this:

    setTimeout(function() {
      window.location.href = "/NewPage.aspx";
    }, 2000);
    
    0 讨论(0)
  • 2020-12-28 13:59

    Would the delay() function not work for you? Vanilla JavaScript with setTimeout() would work equally well.

    Hint: Suggesting actual code is kind of hard when you do not show your current code.

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