Search code examples
htmlscrollhref

scroll top java script function?


In html, Generally people use scrolling to top of page like:

<a href="#top" title="Scroll back to the top">Back to the top</a>

But i need the web page go to top after clicking the link. file of left.php:

<div class"ida0">
   <a href="news.php" target="right_frame"  onclick="scrollToTop()">Link 1</a>
</div>

Because my web page is like this. * main.php * left.php * right.php

|----------------------------|
|----------------------------|
||some image || contents|
||---------------- || of link ||
||---------------- || --------||
||---------------- || --------||
||---------------- || --------||
||-----link1------ || --------||
||-----link2------ || --------||
||---------------- || --------||
||---------------- || --------||

I used this But didn't work.

<script language="javascript">
    function scrollToTop()
    {
   document.getElementById(ida0).scrollTop = 0; //It scrolls to top
    }
</script>

Solution

  • function scrollToTop() {
        window.scroll(0, 0);
    }