setTimeout and window.location (location.href) not working
javascript
Solution
This is the right way...
setTimeout(function(){location.href="index.php"} , 5000);
You can check the docs here:
https://developer.mozilla.org/en/docs/DOM/window.setTimeout
Syntax :
var timeoutID = window.setTimeout(func, [delay, param1, param2, ...]);
var timeoutID = window.setTimeout(code, [delay]);
Example :
WriteDatePlease();
setTimeout(function(){WriteDatePlease();} , 5000);
function WriteDatePlease(){
var currentDate = new Date()
var dateAndTime = "Last Sync: " + currentDate.getDate() + "/"
+ (currentDate.getMonth()+1) + "/"
+ currentDate.getFullYear() + " @ "
+ currentDate.getHours() + ":"
+ currentDate.getMinutes() + ":"
+ currentDate.getSeconds();
$('.result').append("<p>" + dateAndTime + "</p>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="result"></div>
Problem
I want to redirect user to index.php in 5 seconds, but it redirects me right away. I don't want to use jQuery in this simple code. ``` <script> setTimeout(function(){location.href="index.php", 5000} ); </script> ```