Mobile app version of vmapp.org
Login or Join
Cody1181609

: Why doesn't autofocus="autofocus" work in Mozilla Firefox? <INPUT TYPE=TEXT NAME="Gw" MAXLENGTH="225" size="42" autofocus="autofocus"> If I try this with Google Chrome it works. I just want

@Cody1181609

Posted in: #Firefox #Forms #Html5

<INPUT TYPE=TEXT NAME="Gw" MAXLENGTH="225" size="42" autofocus="autofocus">


If I try this with Google Chrome it works. I just want to highlight a form without <script>.

Why doesn't it work?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Cody1181609

3 Comments

Sorted by latest first Latest Oldest Best

 

@Harper822

I try for new some code.
Actually, i use Firefox 34.xx version, but can't still use autofocus.
I Try code above, but didn't work for me, then i try to make own code. i use jquery library.
if you didn' work too, try this code:
HTML

<input type="text" name="searchMenu" placeholder="blaa.. blaaa..." id="searchMenu" autofocus focus>


$(document).ready(function(e) {
$("#searchMenu").focus();
});

10% popularity Vote Up Vote Down


 

@Sent6035632

It's wise to use autofocus with a JavaScript fallback for browsers that don't support it. From Mark Pilgrim's Dive into HTML5 Forms:


What’s that? You say you want your
autofocus fields to work in all
browsers, not just these fancy-pants
HTML5 browsers? You can keep your
current autofocus script. Just make
two small changes:


Add the autofocus attribute to your HTML markup
Detect whether the browser supports
the autofocus attribute, and only run
your own autofocus script if the
browser doesn’t support autofocus
natively.



<form name="f">
<input id="q" type="text" name="Gw" maxlength="225" size="42" autofocus>
<script>
if (!("autofocus" in document.createElement("input"))) {
document.getElementById("q").focus();
}
</script>
<input type="submit" value="Go">
</form>


Live demo here.

10% popularity Vote Up Vote Down


 

@Pope3001725

It should work in Firefox 4. But if you're using an older version of Firefox it won't work as the autofocus attribute is new to HTML5 which only gained broad support in Firefox 4..

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme