Scroll position on web pages not remembered

From MozillaZine Knowledge Base
Jump to navigationJump to search

On some web pages, the browser’s scroll position is not remembered in the session history. For example, if you scroll down the page, click a link, then click the Back button, you’ll be at the top of the page again.

This is a known bug that occurs on some web pages that tell the browser not to cache them.


The Restore Scroll Position extension can fix this problem for Firefox.

Detailed explanation

To prevent a web browser from caching a page, web servers can send a number of HTTP headers to influence caching behavior. In Mozilla, the Cache-Control: no-store header will cause it to purposely forget layout state data — including form values and scroll positions. A more code-oriented analysis is included in the bug report. The current behavior is a regression from the patch for bug 252023.

The Restore Scroll Position extension works around the bug by keeping a separate history of scroll positions outside of the browser’s session history, then manually restoring the scroll position each time a session history entry is loaded (e.g., by pressing the Back or Forward buttons). While this works well for Firefox, a final fix for all Mozilla applications will require changes to nsDocShell and/or PresShell code.

Web developers can avoid having the bug manifest itself on their sites by using alternate headers to prevent caching. For more information, see the FAQ on HTTP caching in Mozilla.

External links