JavaScript: page refresh after timeout

If webpage business logic requires to refresh it after some timeout, the JavaScript function can help. If you use JSF, take a look here to see how to refresh page from Java code.

Put this code in page <head>:

<script type="text/javascript">
	function refresh (timeoutPeriod){ 
		refresh = setTimeout(function(){window.location.reload(true);},timeoutPeriod); 
	} 
</script>

and call it, for example in onclick called on command button or command link. Provide timeout parameter that is time in milliseconds, after which page will be reloaded:

onclick="refresh(2400) "

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

One thought on “JavaScript: page refresh after timeout

Give Your feedback: