Guessing HTML parsing. Nisheeth, can you categorize better?
1) nsWebShell::DoLoadURL recognizes the named anchor click properly and calls nsPresShell::GotoAnchor(). 2) nsPresShell::GotoAnchor() looks up frame associated with the HTML element targeted by the named anchor. It passes the frame as an argument to nsPresShell::ScrollFrameIntoView(). 3) nsPresShell::ScrollFrameIntoView() calculates the x,y coordinates that the root scrollable view (nsScrollPortView) needs to jump to (on my box the coordinates were 0, 7995 which seemed reasonable). It passes those coordinates as arguments to nsScrollPortView::ScrollTo(). 4) nsScrollPortView::ScrollTo() converts twips (0, 7995) to pixels (0, 4050) and gets the scrolled view. It calls the SetPosition method on the scrolled view and passes it the pixel coordinates. *** nsView::SetPosition() ends up doing nothing because the view's mWidget member variable is null***. Maybe this is the cause of the bug. nsScrollPortView::ScrollTo() also calculates the difference between the old and new x,y values. It calls nsScrollPortView::Scroll() with the scrolled view and the x, y differences (0, -270) as arguments. This is something else that I don't understand. Should y be a positive value if the named anchor that we are jumping to is "ahead" of the current document position? I am re-assigning this to Eric Vaughan, scroll guru, for further analysis.
FYI, I've found that provided the anchors are not document.written in an event handler like onload, the anchors do work if done in this manner: var gotoanc = "<a href='#blah'>go to blah</a>"; var anc = "<a name='blah'></a>blah"; ... document.write(gotoanc); ... document.write(anc); i.e. if the string literal does not appear directly as a parameter to document.write but is first assigned to a variable. In an onload or other event handler, even this workaround does not work.
Attaching a simple testcase that works fine for me under Linux x86 build 2000011308 (RH6.0).
Your attachment does work for me. I must have been mistaken earlier. However, anchors still do not work when document.written in an event handler like onload, where the entire page is rewritten, or for that matter (as I gather from reading the newsgroups on this topic) when writing to a new window or frame.
I understand that the document is replaced if document.write is called after an onload, but the bottom line is that you can't document.write anchors after an onload and have the anchors work correcly - which if not a bug, seems like a pretty severe limitation.
putting on beta1 radar
*** This bug has been marked as a duplicate of 25712 ***
vrfy dupe of fixed bug 39716