Original post #1293712: Window should not scroll to top when user is mid-page

Issue Summary

The 'mobile_tools_hide_address_bar' feature is a nice touch, but it scrolls up to the top of the page when a user presses the back button on the browser. When they would normally be back where they were, they are actually scrolled to the top.

function hideAddressBar() {
  window.scrollTo(0, 1);
}

This can be fixed by replacing scrollTo with scrollBy. This will scroll the window down by 1 pixel regardless of where the user is on the page. (Rather than always scrolling the user to 1 pixel from the top of the page.)

window.scrollBy(0, 1);

Alternatively, the call to hideAddressBar() could be wrapped in a an if statement like:

if (jQuery(window).scrollTop() == 0) {
  setTimeout(hideAddressBar, 0);
}

So that it only fires when the window is not at the top of the page. This seems to match intent a bit more, and doesn't result in that small jump unnecessarily, but it's not quite as efficient with jQuery in the mix.

This is actually present in both 6.x and 7.x branches of Mobile Tools.

Comments

devin carlson’s picture

devin carlson’s picture

Status: Active » Closed (duplicate)

There's now a patch at the other issue so I'm closing this one.