Reputation: 14279
I am clicking on a button and reloading the same page with new content. Once the reloading is complete, I want to scroll the document all the way down. How can I do this using jQuery?
$('#loadBtn').click(function () {
//some logic
window.location = url;
window.scrollBy(0, $(document).height())
});
The problem is that scrollBy is getting called before the page is reloaded. I tried chaining after the click event like below, but the scroll is happening after every 'ready' event.
$('#loadBtn').click(function () {
//some logic
window.location = url;
}).on('ready',function() {
window.scrollBy(0, $(document).height())
});
My question is, how do I reload the page, wait for it to load and then scroll the document? Thanks!
Upvotes: 0
Views: 100
Reputation: 2789
Easiest thing that you could do is using #something in url.
window.location = url+'#id_ef_element_you_scroll_to';
And on the 2nd page just find any html tag that you can add id for example
<div id='id_ef_element_you_scroll_to'> ... </div>
Upvotes: 3