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.
Asked
Active
Viewed 6.2k times
4 Answers
80
You can just use setTimeout()
directly, like this:
setTimeout(function() {
window.location.href = "/NewPage.aspx";
}, 2000);

Nick Craver
- 623,446
- 136
- 1,297
- 1,155
4
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";
});

JasCav
- 34,458
- 20
- 113
- 170
-
1Good answer, just consider if its worth marking down as it will wait for 3 seconds, rather than the 2 requested ;) – Paul Hadfield Sep 09 '10 at 14:48
-
3@Paul - Haha...umm...I was demonstrating the power of comments. See...you caught the bug right away because the code was so easy to read! ;-) :-p (I updated the answer to make it two seconds.) – JasCav Sep 09 '10 at 15:04
2
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.

Tomalak
- 332,285
- 67
- 532
- 628
-
I tried what you suggested and it did not work for me. I made a few adjustments which also did not work. Here is where I'm at:
-
@mark: I think your comment was meant for @JasCav's answer. Code formatting works through backticks in comments. – Tomalak Sep 09 '10 at 15:03