How can I scroll the browser at the top after submitting the form in the frame

I have a page with iframe. There is a form in the iframe that targets this frame. The submit button is at the bottom, and the results page is short and appears at the top. Therefore, when the user clicks submit, the form disappears, but they don’t see the results, because they scroll too far.

Instead of just putting a bunch of spaces on the results page, I would like the view to be reconfigured. Is there a way to do this when the user clicks submit?

+3
source share
3 answers

Try the following:

<form onsubmit="parent.scrollTo(0, 0); return true"> ...

I have no idea how cross-browser compatible.

+6
source

Call the javascript function, as shown in the submit form:

function ScrollTop(){
        if (document.all){
        document.body.scrollLeft = 0;
        document.body.scrollTop = 0;
        }
    else{
        window.pageXOffset = 0;
        window.pageYOffset = 0;
        }
}
0
source

Source: https://habr.com/ru/post/1708191/


All Articles