rsturim
rsturim

Reputation: 6846

How to scroll browser view port to top of page after an ajax submit?

I have an upload form -- after the user submits the form, I'd like to scroll the window back to the top of the page (where I display some help text). How do I correctly scroll the window back to the top of the page?

Upvotes: 7

Views: 2844

Answers (3)

Jagd
Jagd

Reputation: 7306

Can you not just use the .focus() event on some tag at the top of the page?

$("input#myFirstName").focus();

Upvotes: 1

Andy West
Andy West

Reputation: 12499

Since you're using jQuery, you could try the ScrollTo plugin, which is highly customizable.

Upvotes: 1

Dónal Boyle
Dónal Boyle

Reputation: 3079

You can use the scroll method on the window object to do this:

window.scroll(0,0)

The arguments are the horizontal and vertical measure of scrolling within the window, so 0,0 brings it back to the top.

Upvotes: 8

Related Questions