How to maintain screen positioning after postback?

0

I have a very extensive html form with multiple entries, after doing postback my page is redirected to the top of the form, how do I, so when is to postback return on the page where I left off? p>     

asked by anonymous 19.01.2015 / 17:36

1 answer

1

You need to save the value of window.pageYOffset ( document.documentElement.scrollTop to IE8) and restore as soon as your page loads again.

If you are using jQuery you can do this:

  • Add a hidden field to store the scroll value
  • <form id="form1">
        ....
        <input type="hidden" name="scrollto" id="scrollto" value="0" />
    </form>
    
  • The code below saves the value of $.scrollTop in scrollto at the time the form is sent and restores the scroll position when the page loads.
  • $(function(){
      $('#form1').submit(function(){ 
         $('#scrollto').val( $(window).scrollTop() ); 
      });
    
      $(window).scrollTop( $('#scrollto').val() ); 
    });
    
        
    19.01.2015 / 19:11