Autofocus doesn't work in iframe after navigation
Categories
(Core :: DOM: Core & HTML, defect, P5)
Tracking
()
People
(Reporter: f2424880, Unassigned)
References
(Depends on 1 open bug)
Details
Attachments
(1 file)
970 bytes,
application/zip
|
Details |
Updated•7 years ago
|
3 years and nothing happening?
I'd just like to add, it seems as if the logic here is that:
-
autofocus gets applied (wherever it is in the document tree) when the top-level window navigates/loads
-
But on navigating or reloading an iframe within an existing document, autofocus is disabled because otherwise it might steal focus from somewhere else in the document.
The latter is certainly a valid concern; you don't want the focus to shift while the user is typing in a input field, for example. However, disabling autofocus altogether for navigating/reloading iframes is too extreme a solution, and can break some essential functionality. For example, consider a website that has a nav-bar and a content area implemented as two separate iframes, and is using autofocus to scroll a serverside-detected user-input error in a form field into view and focus it when the user tries to submit a form containing invalid data, from inside the content iframe: This common use-case no longer works at all.
I propose the following changes to the behaviour of autofocus inside iframes:
-
Even when there's a parent document that already has focus elsewhere (that therefore can't be shifted to the iframe), an autofocus element within an iframe should be SCROLLED INTO VIEW within that iframe, despite not being able to be given the focus.
-
If an element within an iframe has focus, and then that iframe navigates or reloads, and if focus is not captured by any element in the parent document (or document tree) during that process, then autofocus should be honoured within the iframe. In particular, if you simply click a link or a submit button inside an iframe and don't interact further with the browser, then (assuming no scripts change the focus element) when the iframe finishes (re-)loading, if it's document contains an autofocus element, focus SHOULD be given to that element.
-
Additionally, there should probably be an attribute you can set on the iframe to control whether autofocus within the iframe works (i) always, (ii) never, (iii) only on the initial top-level load, or (iv) as just described above (which should be the default).
So... what are the chances someone will take some action on this within the next three years...?
![]() |
||
Comment 2•5 years ago
|
||
It's as if autofocus is only applied when the top-level browsing context is navigated
That is precisely correct, yes. Autofocus is not applied after the toplevel document is done loading right now, to avoid focus-stealing behaviors.
I notice nothing happening here for a couple of years...
Might I respectfully suggest again that autofocus should still scroll the autofocused element into view, even if you can't or won't apply the actual focus?
This can be important for page authors who rely on it to bring something to the user's attention, like a form field error, that might start off scolled out of view.
Updated•2 years ago
|
Description
•