Vlad Vlad - 6 months ago 10
Javascript Question

How to place page on top after the reload?

var $form = $('form');
$form.submit(function() {
$.post($(this).attr('action'), $(this).serialize(), function(response) {
alert("Your form is submitted");
location.reload();
}, 'json');
return false;
});


How do I place the user at the top of the page after I forced
location.reload();
?

Thanks

Answer
$('body').scrollTop(0);
location.reload();

That will take the page to the top after your alert and then reload which will load the page where it left off (at the top in this case).