Delay automatic url redirect with jquery?

2019-02-02 07:17发布

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条回答
狗以群分
2楼-- · 2019-02-02 07:57

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";
});
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-02 08:13

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

setTimeout(function() {
  window.location.href = "/NewPage.aspx";
}, 2000);
查看更多
趁早两清
4楼-- · 2019-02-02 08:13
setTimeout(function(){ window.location = "/NewPage.aspx"; }, 2000);
查看更多
手持菜刀,她持情操
5楼-- · 2019-02-02 08:16

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.

查看更多
登录 后发表回答