Wednesday, November 3, 2010

Javascript: autoscroll scroll bottom page

I have page which returned process of huge DB records. The records were flushed in interval to so I can see records progressing. Each time page refreshed, I have to scroll the page down to bottom to see latest record. Which is troublesome to do it repetitively.

So I created a script using javascript that manipulate anchor tag to always scroll page to bottom. It made the page looks like progressing log. Anchor tag is set at the beginning of a loop, execute function to call the anchor before loop end. Here is the example(using Coldfusion):-

<cfloop query="hdrInfo"> <!--- loop query --->
<cfset counterxx = counterxx+1>
<a name="#counterxx#"></a>
    Things to be display
    ...
    ...
<cfflush interval="10"> <!--- set flush interval 10 seconds --->
<a href="###counterxx#" id="rec#counterxx#"></a>
<script language="javascript">
    document.getElementById('rec#counterxx#').click();
</script>

Get the concept and you can apply it in other web application.
Appreciate any comment. Thank.

Designed by Posicionamiento Web | Bloggerized by GosuBlogger | Blue Business Blogger