redirect to home page after 3 seconds

11,345

Solution 1

You can use setTimeout to set time after which user will be redirected and window.location to set the URL where the users should be redirected

setTimeout(function(){ window.location = "http://www.yoururl.com"; },3000);

Solution 2

<script type="text/javascript">
        $(document).ready(function () {
            setTimeout(function () {
                window.location = "you Home Page URL";
            }, 3000);
        });
    </script>
Share:
11,345

Related videos on Youtube

ace
Author by

ace

Beginner at programming :)

Updated on June 04, 2022

Comments

  • ace
    ace almost 2 years

    i created a simple login that the user will fill in and after successfully login he will redirectly go another page that has a message login successful, Now my problem is after the user redirect to the login success massage page is there a way to set 3seconds on that page and after that the user will go back to home page after 3 seconds? hope you can help me. Thanks

    • Pedro Sturmer
      Pedro Sturmer almost 6 years
      That's not the right way to do it, but you can use setTimeout(function(){ window.location = '/home'}, 3000), for this kind of requests i recommend you learn more about promises
    • karthick
      karthick almost 6 years
      just out of curiosity why can't you show your homepage directly?
    • Alex Howansky
      Alex Howansky almost 6 years
      This is poor UI design, don't make the user wait for anything. Just redirect back the home page immediately. Logging in should only generate an unavoidable message if the login fails.
    • ace
      ace almost 6 years
      im just doing what my adviser want. haha
    • Fobos
      Fobos almost 6 years