0

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>

2 Answers 2

4
function scrollToTop() {
    window.scroll(0, 0);
}
Sign up to request clarification or add additional context in comments.

2 Comments

when i put the code "window.scroll(0, 0);" in the "left.php" file, and clicked the link, it worked well, went to the top of window. But when i opened main.php, and clicked the link in left.php it didn't worked.
@trante: Try window.top.scroll(0, 0);.
1

If you want to jump instantly to the top, you can use window.scrollTo(0, 0), or if you would like to animate the scroll, you can use something like jQuery.smoothScroll.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.