Incorrect named anchor scrolling position when stylesheet linked via DOM manipulation




9 years ago
9 years ago


(Reporter: will.lynn, Unassigned)


(Depends on: 1 bug, {testcase})

Firefox Tracking Flags

(Not tracked)


(Whiteboard: DUPEME, URL)



9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv: Gecko/2009011913 Firefox/3.0.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv: Gecko/2009011913 Firefox/3.0.6

In the demo page

The two pages linked via named anchors are identical except that the main.css file is referenced with a static LINK tag in the first and added using JavaScript via the DOM in the second page. The named anchor doesn't work in the second page if you visit it from the first page, but will work if you visit it from inside the second page when it is already loaded.

Tested in FF 2 and FF 3.06. All the html and CSS validates. The scrolling position for both pages works fine in IE/Opera/Safari.

Reproducible: Always

Steps to Reproduce:
1. Visit
2. Click on the link to page 2. You will be scrolled to the bottom of the page instead of the position of the named anchor.
Actual Results:  
Firefox does not scroll to the correct position.

Expected Results:  
Firefox should scroll to the correct position regardless of how the CSS is referenced. Other browsers do.

This seems to occur when there is a height:[number]px element and display:none although I have not determined all instances where this happens. This is not affected by very simple layouts.

If you browse to page2.html and then go to the anchor, Firefox scrolls to the correct anchor position.

Tested on Windows 2000, XP and Server 2003 on FF 2 and 3.06 versions.

Comment 1

9 years ago
"This is not affected by very simple layouts." - sorry this is ambiguous, I meant that simple CSS layouts do not cause a problem with the anchor scrolling position.

Comment 2

9 years ago
Also happens with a recent (2.0b3pre ( 2009022319)) build of Camino running under Tiger-PPC (Mac OS X 10.4.11).  Have not checked this with Leopard (Mac OS X 10.5.x) or Intel Mac.

Comment 3

9 years ago
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2a1pre) Gecko/20090225 Minefield/3.2a1pre

I can reproduce this bug 80% of the time.

Maybe Firefox isn't taking the stylesheet load into account when deciding whether the page is "done" enough to do the final anchor scroll?  It is added by an inline script, so I'd expect it to be taken into account.

The testcase is good, but it would be even better if you could make one that uses and attach it so we can be sure it doesn't get lost.
Component: General → Layout
Ever confirmed: true
Keywords: testcase
Product: Firefox → Core
QA Contact: general → layout
The anchor scroll happens on parse completion, not onload.  You get the same issue with an anchor below some slow-loading images, and we have existing bugs on that...
Whiteboard: DUPEME

Comment 6

9 years ago
Apologies if this is a duplicate. I did search for a similar bug before I reported this but I'm not too familiar with the internal workings of FF (such as anchor scroll happening on parse completion).

Comment 7

9 years ago
And I guess the reason this doesn't happen in the non-script case is that the stylesheet load blocks layout?
Will, not a problem.  It's not obvious that this is a duplicate by any means, unless you know how the code works!

Comment 7 is right.
Depends on: 43114
You need to log in before you can comment on or make changes to this bug.