Michael Banucu Michael Banucu - 11 months ago 46
Javascript Question

strange behaviour of Chrome at window.scrollTo()

i'm using this:

<meta http-equiv="refresh" content="5; URL=<?php $_SERVER['PHP_SELF'] ?>">

for reloading the page every 5 seconds.

i'm using this:

<script type="text/javascript">
window.scrollTo(0, document.body.scrollHeight);

for scrolling down if necessary.

It works fine with Firefox and Internet Explorer but Chrome scrolls only once when loading the page for the first time. Only when I switch the tab (e.g. Ctrl+t) and go back after 5 seconds (Ctrl+w) Chrome scrolls down to the bottom. This is strange! Do I use window.scroll incorrectly or does Chrome behave incorrectly?

Are there any other possibilities for scrolling to the bottom?


I found the problem: While the page is loading, Chrome has a problem with scroll commands. Solution:

<body onload="setTimeout(function(){window.scrollTo(0,document.body.scrollHeight)}, 1000);">

This works, if loading of page doesn't last more than 1 second (1000 milliseconds).