Autofocus Attribute of HTML5 does not work only in FireFox when <Form><input> are loaded via Ajax. WHY?

。_饼干妹妹 提交于 2019-11-29 13:51:50

Autofocus is only done before onload has fired; it's meant to be a declarative way of specifying focus on initial page load.

use settimeout after ajax call on the div, or using jquery use .ajaxComplete, or .done

function theAjax(){
//after the ajax actions loaded......
//use settimeout to refocused on the input..
var t=setTimeout("focusMe()",500);

}

function focusMe(){
document.getELementById("theInput").focus();  //the new input

}

//using jquery use .ajaxComplete, or .done
 $( document ).ajaxComplete(function() {
   $("#focusOnMe").focus();
 }

I know this is old, but I just had this problem and maybe it helps someone.

If you use jQuery this works:

$("input[name='c_name']").focus();

Javascript would be something like this (general example):

document.getElementById('element').focus();

But you have to call that function after your form is loaded via ajax!

JuliaCesar

I have the absolutely same problem: the Autofocus attribute doesn't work in FF, at least in the latest version. I also have a pop-up window with a form. Ajax is used for this pop-up initiation.

I hope these links will be helpful to you:

Discussion on webmasters.stackexchange.com

Another discussion on stackoverflow

But I haven't found out any more simple and good looking solution except by using javascript hacks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!