User Agent: Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0
Build ID: 20130104151925
Steps to reproduce:
Having an input box with autofocus in the beginning of the pages, and then having an anchor(s) later in the page.
Linking to an anchor inside the page from an external page would fail to jump to the anchor. Clicking again after the page loads will jump to the anchor.
The browser should jump to the anchor even if the autofocus exists. IE and Chrome does the right behavior.
Removing the autofocus gets firefox to jump to the anchor directly.
Please, attach a minimal testcase (online if you want), so we could test.
Dupe for Bug 668213 (which proposed to dupe with bug 633821)?
Created attachment 714072 [details]
Test case where autofocus for the input box will override the anchors.
Created attachment 714074 [details]
Test case where autofocus was removed from the input box. Now anchors work.
Try to reach an example anchor #Q using this file and using the other file with autofocus. The first time to reach this anchor will fail if there is an autofocus, if you try AGAIN while the page is LOADED. The browser will jump.
Works for me with
I can confirm the behavior in Firefox 34.0 (Mac OS X 10.8.5) and Firefox Nightly 37.0a1 (2014-12-20). My test is available at http://medialize.github.io/ally.js/tests/browser-bugs/blink-autofocus.html#foo
I can also add that Blink (not WebKit) has the same issue: https://code.google.com/p/chromium/issues/detail?id=382901
When both, autofocus and fragment-anchor are present, the following event sequence is played:
init (synchronous script at end of document)
The fragment's target (`:target`) is only accessible after DOMContentLoaded, the autofocus element receives focus *before* the document enters interactive state.
Disabling the autofocus by adding the following script to the end of the document has will cause the <input> to not have that attribute anymore, but is still focused right away:
There is no way to *prevent* the <input> from receiving focus, you can only blur it, and move the document back to the :target (using Element.scrollIntoView ) after the fact.
> Disabling the autofocus by adding the following script to the end of the document has will
> cause the <input> to not have that attribute anymore, but is still focused right away:
While that holds true, removing the [autofocus] element will, of course, issue a blur event, making <body> the activeElement and fragment target remains in the viewport.
After pressing <kbd>Command R</kbd> to reload the document, scroll position moves to the beginning, as if the [autofocus] element was moved into viewport. This does not happen with <kbd>Command Shift R</kbd>.