Michael Banucu
Michael Banucu

Reputation: 219

strange behaviour of Chrome at window.scrollTo()

i'm using this:

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

for reloading the page every 5 seconds.
i'm using this:

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

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?

Upvotes: 1

Views: 5418

Answers (2)

Michael Banucu
Michael Banucu

Reputation: 219

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).

Upvotes: 1

dsgriffin
dsgriffin

Reputation: 68586

Have you tried using window.scroll() as an alternative?

window.scroll(x, y);

Upvotes: 0

Related Questions