HTML5 autofocus = autoselect?

Fer picture Fer · Jan 19, 2011 · Viewed 14.2k times · Source

I'm using some HTML5 form features to progressively enhance the user experience of my web project. One in particular is autofocus, I'm wanting to use this in a modal (lightbox) dialog that allows users to enter tags. Existing tags could be there.

The only browser I have installed that supports autofocus is Chrome 9, however when I test it there it does place the focus on the field, but also automatically selects all existing text in the field. I did not expect or want autoselect, I want autofocus.

Is my expectation wrong or is Chrome wrong?

Answer

Pascal_dher picture Pascal_dher · Jul 22, 2014

Chrome decided they were wrong and changed this behaviour in Chrome 36.

I know this because I was wrongly relying on javascript .focus() and html autofocus for also selecting the text. Now it requires a .select() to select and focus in the text field. Good that we can now be specific of what we want :-)

So now Chrome behaves like e.g. Firefox.