I was charged with the task of implementing a dialog for displaying errors in a legacy application. My solution involves an error management object being defined and instanciated on the head section; then, whenever the backing PHP code gets an error, it will generate a script block calling a method in my error manager; and finally, in the bottom of the page, there is a call to a manager method that displays a dialog (from jquery UI) if any errors were set.

Problem is, by the time the method that fires the dialog is called, the page isn't completely loaded yet. So if this happens after the user refreshes the page while they're halfway through the scroll, for instance, after the page is fully loaded, the browser goes about placing the scroll back where it was before the refresh.

I know I can set the scroll back to the top with jQuery's scrollTop(), I just don't know when to do it. I've tried the $(window).load() handler, but it seems the browser goes about resetting the scroll after the window onload event has fired.

The best I could come up with was scrolling back up after a timeout, but that seems really inelegant and, in all fairness, doesn't really work everytime. What am I missing here?

  • Most browsers will handle it with either $(window).load or $().ready() but Chrome doesn't seem to like either... Ktash over 7 years ago
  • Yeah, there doesn't seem to be a consistency among browsers in that regard. I solved the problem by setting the dialog to a fixed position, but I was curious about this matter anyway. Oh well. Guilherme Ventura over 7 years ago