Reputation: 1862
Internet explorer scrolls down the page automatically on page refresh and puts focus where I was before refresh. I have tried following things to override this behavior BUT nothing worked :
$(window).on('beforeunload', function() {
$(window).scrollTop(0);
}); // option 1
window.onload = function () {
jQuery('body').css({'overflow': 'auto', 'position': 'static'});
window.scrollTo(0, 0);
}; // options 2
I have "h1" tag at the top of the page and I tried to put focus on the that element too by this code :
$( document ).ready(function() {
document.getElementById('pageHeader').focus();
}); // Option 3
Above all code executes BUT after all this IE throws focus where I was before refresh. My problem is I am using screen reader to read the page content so I want the page to scroll to TOP on each page refresh. Everything works fine on Chrome. Please help me.
Upvotes: 0
Views: 2657
Reputation: 19113
This should work in all browsers...
$(window).on('load', function() {
$(window).scrollTop(0);
});
Upvotes: 1