View Full Version : focus() method fails on FF?

08-21-2010, 05:23 PM

does 'focus' method show a 'stable' result? i call this method on a node -- if this one is not absolutely positioned -- it seems nothing happens
so ① does this method only apply to absolutely positioned element?

also, in FF, aNode.focus() has no effect whereas in IE document will scroll until that node is visible if the node is partially invisible at the bottom.
②is this a bug in FF?

here is the code

<div style="position:absolute; left:50px; top: 700px" onclick="this.focus();">
yepsfagadgre<br />agefderdsf<br />agefderdsf<br />agefderdsf</div>

scroll the document until the text is half-visible at the bottom. click on it -- in IE it will scroll up while in FF nothing happens
besides, if it is not absolutely positioned, nothing happens either~~~

thx in advance

Philip M
08-21-2010, 06:51 PM
There is a bug in Firefox.

You need to introduce small delay:-

setTimeout("document.formname.fieldname.focus()", 25);
setTimeout("document.getElementById("fieldname").focus()", 25);

if document.formname.fieldname or document.getElementById() is a variable, then that variable must be global.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

08-21-2010, 07:05 PM
thanks Philip
i just wonder why there needs a delay for FF? any underlying mechanism?

also, why non-absolutely positioned element cannot gain 'focus' (calling focus method yields no result)

Philip M
08-21-2010, 07:51 PM
i just wonder why there needs a delay for FF? any underlying mechanism?

Because as I say there is a big in Firefox - focus() does not work unless there is a short delay.