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.
+1
A:
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
2010-09-09 14:45:14
Good answer, just consider if its worth marking down as it will wait for 3 seconds, rather than the 2 requested ;)
Paul Hadfield
2010-09-09 14:48:46
@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
2010-09-09 15:04:44
+2
A:
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
2010-09-09 14:47:18
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: <code> <script type="text/javascript">$(document).ready(function(){alert('works!');// This will hold our timermed = "http://www.zhospitalitygroup.com/mediterraneo/press/";var myTimer = {}; // delay 3 seconds myTimer = $.timer(1000, function() { //redirect to home page document.location = med;});});</script><code>
mark
2010-09-09 14:56:27
@mark: I think your comment was meant for @JasCav's answer. Code formatting works through backticks in comments.
Tomalak
2010-09-09 15:03:47
+2
A:
You can just use setTimeout()
directly, like this:
setTimeout(function() {
window.location.href = "/NewPage.aspx";
}, 2000);
Nick Craver
2010-09-09 14:50:13
A:
Do you use jQuery 1.4.2? Because older versions don't support delay() yet.
Litso
2010-09-09 15:04:37