Skip to content

Commit ebaf920

Browse files
author
Stephen Gutekanst
committed
Only blur/refocus elements if they are within the PJAX container.
This can be useful if using PJAX to reload the contents of a search page, for instance. See #377
1 parent c70ffe2 commit ebaf920

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

jquery.pjax.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,15 @@ function pjax(options) {
292292
window.history.replaceState(pjax.state, container.title, container.url)
293293
}
294294

295+
// Only blur the focus if the focused element is within the container.
296+
var blurFocus = $.contains(options.container, document.activeElement)
297+
295298
// Clear out any focused controls before inserting new page contents.
296-
try {
297-
document.activeElement.blur()
298-
} catch (e) { }
299+
if (blurFocus) {
300+
try {
301+
document.activeElement.blur()
302+
} catch (e) { }
303+
}
299304

300305
if (container.title) document.title = container.title
301306

0 commit comments

Comments
 (0)