2 Replies - 4356 Views - Last Post: 06 April 2013 - 03:44 PM

#1 hardcoder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-November 12

Redirecting to page after a specified time

Posted 06 April 2013 - 12:39 PM

Based on the example I saw here :
http://stackoverflow...-specified-time

I'm trying to redirect to another page after a second has passed. (I am starting to count when the document has loaded).
I cannot seem to spot the problem in this code, any help you could give me would be appreciated :

<body>
    <p>Login Failed!</p>
    <p>Redirecting you back to the login screen.</p> 
    <p>Reason: Incorrect Password or Username.</p>
    <script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.5.js" type="text/javascript">
        $(document).ready(function () {
        var delay = 1000; //Your delay in milliseconds
        setTimeout(function(){ window.location.href = "LoginPage.cshtml"; }, delay);
        });
    </script>
</body>


Is This A Good Question/Topic? 0
  • +

Replies To: Redirecting to page after a specified time

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Redirecting to page after a specified time

Posted 06 April 2013 - 03:25 PM

Try this.

<html>
  <head>
    <script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.5.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
        var delay = 1000; //Your delay in milliseconds
        setTimeout(function(){ window.location.href = "LoginPage.cshtml"; }, delay);
        });
    </script>
  </head>
  <body>
    <p>Login Failed!</p>
    <p>Redirecting you back to the login screen.</p> 
    <p>Reason: Incorrect Password or Username.</p>
  </body>
</html>


This post has been edited by JackOfAllTrades: 06 April 2013 - 03:29 PM
Reason for edit:: Placed code in head

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Redirecting to page after a specified time

Posted 06 April 2013 - 03:44 PM

Could just put the setTimeout at the bottom of the page, before the closing body tag, and not bother with jQuery.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1