Skip to content

Commit 8917533

Browse files
committed
Fix autofocus in FF
/cc @jonrohan
1 parent 3fef6e7 commit 8917533

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jquery.pjax.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ function pjax(options) {
263263

264264
if (container.title) document.title = container.title
265265
context.html(container.contents)
266+
267+
// FF bug: Won't autofocus fields that are inserted via JS.
268+
// This behavior is incorrect. So if theres no current focus, autofocus
269+
// the last field.
270+
//
271+
// http://www.w3.org/html/wg/drafts/html/master/forms.html
272+
var autofocusEl = context.find('input[autofocus], textarea[autofocus]').last()[0]
273+
if (autofocusEl && document.activeElement !== autofocusEl) {
274+
autofocusEl.focus();
275+
}
276+
266277
executeScriptTags(container.scripts)
267278

268279
// Scroll to top by default

0 commit comments

Comments
 (0)