What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

scroll to bottom of page with <body onload

mmacgowa

New member
I am a newb. I am developing a web site that writes log entries to a simply HTML file. Various users will run PHP pages that will create entries on the log page. I want a user monitoring the log file to see the new entries made at the bottom. The entries are not occurring fast so I have created a meta tag to refresh the page every three minutes. I am not familiar with JS but was able to find a simple function that scrolls. I would like to tighten up the code. First is there a way to specify percent instead of pixels? I can specify a large pixel jump but as the log grows, I may miss the end of the file where the latest entries are. The other issue is that having a delay too long misses the refresh so there is never a scroll. The delay must be less than the three minutes before the page is redrawn. If the delay is too short, a user will not be able to scroll back in the document to review the data. I tried eliminating the delay so that the code will execute only when the page refreshes, but it did not work without the delay line.

<html><head><meta charset='UTF-8'><meta http-equiv='refresh' content='120' >
<script>
function pageScroll() {
window.scrollBy(0,10000);
scrolldelay = setTimeout('pageScroll()',10000);
}
</script>
</head>
<body onLoad="pageScroll()">
content
 
Back
Top