location.href="#ANCHOR_NAME" should scroll page to specified anchor




17 years ago
17 years ago


(Reporter: reliqnet, Assigned: jst)


Windows 2000

Firefox Tracking Flags

(Not tracked)





17 years ago
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
BuildID:    2001080303

I have an HTML page, and on the page, I have defined the following JavaScript:

<script language="javascript">
	location.href = "#bottom";

On page load, this bit of JavaScript SHOULD take me to the place on the page 
anchored by the "bottom" tag (i.e., <a name="bottom">bottom of the page</a>), 
but it does not.  I have to hit the REFRESH button for this to happen.

Reproducible: Always
Steps to Reproduce:
1. Go to page.
2. Witness nothing happen.
3. Hit REFRESH, and page does as it should (reflows).

Actual Results:  Nothing happens.

Expected Results:  Page should reflow to place on page with anchor tag.

IE, Opera, and Netscape 4.x all do the right thing and reflow the page.  
Mozilla does not.
-> DOM Level 0

Changing "reflow" to "scroll" in the summary.
Assignee: rogerl → jst
Component: Javascript Engine → DOM Level 0
QA Contact: pschwartau → desale
Summary: location.href="#ANCHOR_NAME" should reflow page to specified anchor → location.href="#ANCHOR_NAME" should scroll page to specified anchor
Confirming, Win NT build 2001080603.
Ever confirmed: true

Comment 3

17 years ago
Does this break existing web-pages? I would argue that mozilla does the right
thing here, you're asking it in the head of the document to scroll to something
that hasn't been seen by the parser yet, mozilla looks for the thing to scroll
to, but doesn't find it and doesn't scroll anywhere. The "right" way to do what
the testcase does is to do the scrolling from the onload handler on the page, i.e.:

  <body onload="location.href='#bottom';">

Re-open and show us a real page that breaks because of this and we'll reconsider.
Last Resolved: 17 years ago
Resolution: --- → WONTFIX


17 years ago
Resolution: WONTFIX → ---

Comment 4

17 years ago
>>> you're asking it in the head of the document to scroll to something
that hasn't been seen by the parser yet <<<

Well, I could have just as simply placed the JavaScript at the very bottom of
the HTML code, after the ending </html> tag.  Would that warrant fixing the bug?
 Mozilla still doesn't do the right thing if the script is located at the very
bottom, and is read after the parser's gone through everything.  I've already
tested this, but so that you can see it, I'll update my sample page tomorrow
morning when I get to the office.

Comment 5

17 years ago
Updated so that JavaScript occurs at the end of the page (after the parser has
read everything):



Comment 6

17 years ago
I'm still not convinced that I wanto fix this (now the testcase has the script
tag *after* the end </html> tag, this is invalid HTML, btw). Why don't you just
set the lo cation from the onload handler in the document?

Again, show me existing pages that break due to this and I'll re-think...

Comment 7

17 years ago
I did use the onLoad, eventually, but I figured I'd report the odd behavior 
anyway.  It's just strange because the browser goes to the right location 
(page.html?#place), but the browswer window just doesn't scroll to it, which I 
found a bit odd.
Last Resolved: 17 years ago17 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.