Initial focus in Chrome

I’ve seen numerous posts related to focus, but have not found a solution as yet. Any help is appreciated.

Scenario I have an ASP.NET web page with a user name and password input control. I pre-load the user name input from AD and want to set initial focus to the password field. This work great in IE, but no matter what I’ve tried with Chrome, it won’t set focus to the password field when the page initially loads. Initial focus is always in the Chrome address bar. If I press the enter key to postback the page, focus to the password input works correctly.

What I’ve done so far in a document.ready event, I make a call to the setInterval function with a delay of 500ms. The function called gets a reference to the password input and calls focus. I’ve changed the delay all the way up to 1000ms, but still no focus.

I’ve also tried setting the tabindex on the password input to 0 or 1.

It’s like there is some internal function in Chrome that waits until everything is complete in your page and then sets focus to the address bar.

Add Comment
2 Answer(s)

If you are using HTML5 then you can try with autofocus

<input type="password" id="pswdId" autofocus>

Answered on August 30, 2020.
Add Comment

I find that in the on-load (code behind), you can set the focus like this:

    Me.TextBox2.Focus() 

Of course the control will need a "id" and runat="server"

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.