I have a HTML with following script:
<script type="text/javascript">
function doRefreshWithInterval() {
setTimeout("doRefresh()", 60000 );
}
function doRefresh() {
window.location.reload(true);
}
if (window.location.href.indexOf("Dashboard.jspa") >= 0) {
doRefreshWithInterval();
}
</script>
To make a page refresh periodically. The problem is when I scroll down the page (it is a long page), and refresh happens on some browsers (specially Firefox) the browser goes to top of the page and not where I was. Is there some way to prevent this, and make Firefox scroll down to the last position after refresh?
Actually, you only need to make one tiny change to your existing code. Change
document.location.reload(true);todocument.location.reload();.Using
trueyou force the browser to get the page from the server again, which means your place on it will be lost. When you remove thetrue, the browser loads the page from the cache, preserving your place on the page.This may not be helpful, however, if the reason you’re automatically reloading the page is to get the latest version of the page that the server may have modified.
Tested with Firebug in Firefox 12.0.