I have finished developing my website and I am testing it. I run a script after 1 second to check the height
of the header/top and add a margin-top
to the content section. but this header/top changes sizes depending on the scroll position (on runtime). So first I have to make sure the page scroll is set to (top) 0 and then run this script. Sometimes the user has scrolled down and refreshed, and the natural browser's behavior is to scroll the page to where it was.
After several attempts on Google Chrome and after commenting most of my code that is triggered when page loads, I tried the same on Firefox and it works! So this code doesn't work on Chrome:
$(document).scrollTop(0);
// or this
$(document).ready(function(){ $(this).scrollTop(0); });
I used the animate
function and passed a callback to alert
"Hello" and it alerts on top, then I click "Ok" and it goes back to where the scroll was before the refresh.
I also tried without jQuery and nothing happens
window.scrollTo(0,0);
On Firefox it works fine. No Javascirpt code is running BUT the scrollTop
(maybe things like social plugins, but nothing mine).
Does anybody know a workaround or how to fix it? Whats the matter with Chrome?