How can I use interval in js? For example I want to call a function every 5 seconds?
<script type="text/javascript">
setInterval(openAPage(), 5000);
function openAPage() {
var startTime = new Date().getTime();
var myWin = window.open("http://www.sabah.com.tr","_blank")
var endTime = new Date().getTime();
var timeTaken = endTime-startTime;
</script>
This script doesn't work, anyone know why?
These answers are thorough and good; I just want to specifically fix yours. See the other answers for HOW/WHY.
Note the lack of
()
.Also, you're missing the closing
}
on the openAPage() function.And if you need to pass data to the function, you can do it with a closure:
will print "hello" to the console.