views:

154

answers:

4

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
Good answer, just consider if its worth marking down as it will wait for 3 seconds, rather than the 2 requested ;)
Paul Hadfield
@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
+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
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
Sorry, I can't figure out how to format the code. Any ideas?
mark
@mark: I think your comment was meant for @JasCav's answer. Code formatting works through backticks in comments.
Tomalak
+2  A: 

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

setTimeout(function() {
  window.location.href = "/NewPage.aspx";
}, 2000);
Nick Craver
Thank you so much! Works great!
mark
A: 

Do you use jQuery 1.4.2? Because older versions don't support delay() yet.

Litso