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
Asked
Active
Viewed 1.3k times
2
-
1That'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 – Pedro Sturmer Aug 02 '18 at 18:29
-
just out of curiosity why can't you show your homepage directly? – karthick Aug 02 '18 at 18:31
-
1This 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 Aug 02 '18 at 18:32
-
im just doing what my adviser want. haha – ace Aug 02 '18 at 18:36
-
Possible duplicate of [Page Redirect after X seconds wait using JavaScript](https://stackoverflow.com/questions/17150171/page-redirect-after-x-seconds-wait-using-javascript) – Fobos Aug 02 '18 at 18:38
2 Answers
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.com"; },3000);

alt255
- 3,396
- 2
- 14
- 20
1
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () {
window.location = "you Home Page URL";
}, 3000);
});
</script>

Vishal Lunagariya
- 40
- 8