开发者

Delay automatic url redirect with jquery?

开发者 https://www.devze.com 2023-01-15 17:40 出处:网络
I need a transition page that will display for 2 seconds before automatically redirecting to the home pa开发者_开发百科ge. How do I do this? I can\'t seem to get delay to work for me.You can just use

I need a transition page that will display for 2 seconds before automatically redirecting to the home pa开发者_开发百科ge. How do I do this? I can't seem to get delay to work for me.


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

setTimeout(function() {
  window.location.href = "/NewPage.aspx";
}, 2000);


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


setTimeout(function(){ window.location = "/NewPage.aspx"; }, 2000);


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

精彩评论

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

关注公众号