scrollTo scrolls to the top of the page

Posted by yanis on Stack Overflow See other posts from Stack Overflow or by yanis
Published on 2010-03-27T21:04:47Z Indexed on 2010/03/27 21:13 UTC
Read the original article Hit count: 347

Filed under:
|
|

Hi, I have the following Javscript code. When the page is loaded it is scrolled to the right position. When I click on the link to run the function the page scrolls to the top of the page. Has anybody any idea how to fix it?

<html>
    <head>
        <script  type="text/javascript">
            function scroll() {
                window.scrollTo(0, 400)
            }
        </script>
        <title></title>
    </head>
    <body onload="window.scrollTo(0, 400)">
        <img src="a.jpg"/>
        <a href="#" onclick="scroll">comments1</a>
    </body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about scrollto