Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autofocus doesn't work on Firefox and doesn't work when coming from another page

I'm creating my page using Javascript. It is a login page and I need to use autofocus on username input text. This operation works on IE and Chrome, but doesn't on Mozilla! This is the HTML I have been adding using JS:

'<input id="username" class="loginInput" data-bind="value: userName, valueUpdate: \'afterkeydown\'" type="text" name="User" autofocus><!--User Input text end /-->'

When i load the page with Mozilla this input is set this way:

<input id="username" class="loginInput" type="text" autofocus="" name="User" data-bind="value: userName, valueUpdate: 'afterkeydown'">

I really can't understand why autofocus attribute is set in that way. I even tried by adding the attribute using JQuery $("#username").attr('autofocus','autofocus') and works only on Chrome and IE.

The second problem comes when I go to the login page from another page and autofocus issue comes with every browser.

Can you help me?

like image 489
user1423142 Avatar asked Oct 14 '14 15:10

user1423142


People also ask

How do I turn on autofocus in HTML?

The autofocus attribute is a boolean attribute. When present, it specifies that an <input> element should automatically get focus when the page loads.

How do I turn off JavaScript in Firefox?

On Android, tap the entry, then tap the toggle to disable JavaScript in Firefox. JavaScript is now disabled in your Firefox browser. To re-enable it at any time, change the value of javascript.

How do I enable JavaScript in Firefox on my Iphone?

In the Apple/System bar, select the Firefox menu item; then pick Preferences... from the drop-down menu. Select the Content icon/tab and mark the Enable JavaScript checkbox.


1 Answers

You can try with:

$("#username").focus();

after the page has been loaded.

like image 128
jorgeromero Avatar answered Sep 28 '22 07:09

jorgeromero