admin管理员组

文章数量:1323348

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

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

Share Improve this question asked Aug 2, 2018 at 18:28 aceace 1481 gold badge3 silver badges17 bronze badges 5
  • 1 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 remend you learn more about promises – Pedro Sturmer Commented Aug 2, 2018 at 18:29
  • just out of curiosity why can't you show your homepage directly? – karthick Commented Aug 2, 2018 at 18:31
  • 1 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. – Alex Howansky Commented Aug 2, 2018 at 18:32
  • im just doing what my adviser want. haha – ace Commented Aug 2, 2018 at 18:36
  • Possible duplicate of Page Redirect after X seconds wait using JavaScript – Fobos Commented Aug 2, 2018 at 18:38
Add a ment  | 

2 Answers 2

Reset to default 4

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."; },3000);
<script type="text/javascript">
        $(document).ready(function () {
            setTimeout(function () {
                window.location = "you Home Page URL";
            }, 3000);
        });
    </script>

本文标签: javascriptredirect to home page after 3 secondsStack Overflow