Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to control the browser scrolling using JavaScript/jQuery? It was scroll to last but it was not able to scroll to the top. Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

You can use the below code for onload:

// This prevents the page from scrolling down to where it was previously.

if ('scrollRestoration' in history) {

    history.scrollRestoration = 'manual';

}

// This is needed if the user scrolls down during page load and you want to make sure the page is scrolled to the top once it's fully loaded. This has Cross-browser support.

window.scrollTo(0,0);

I hope this will help.

Want to become a Java Expert? Join Java Course now!!

Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 12, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...