Skip to content

Commit 2dfe85d

Browse files
committed
Dialog: Safe activeElement access.
Fixed #9420 - Dialog: Close causes blur of window in IE9 Fixed #8443 - Dialog: "unspecified error" when using ie9 and iframe
1 parent ec3cf67 commit 2dfe85d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

ui/jquery.ui.dialog.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ $.widget( "ui.dialog", {
169169
enable: $.noop,
170170

171171
close: function( event ) {
172-
var that = this;
172+
var activeElement,
173+
that = this;
173174

174175
if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
175176
return;
@@ -179,10 +180,22 @@ $.widget( "ui.dialog", {
179180
this._destroyOverlay();
180181

181182
if ( !this.opener.filter(":focusable").focus().length ) {
182-
// Hiding a focused element doesn't trigger blur in WebKit
183-
// so in case we have nothing to focus on, explicitly blur the active element
184-
// https://bugs.webkit.org/show_bug.cgi?id=47182
185-
$( this.document[0].activeElement ).blur();
183+
184+
// support: IE9
185+
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
186+
try {
187+
activeElement = this.document[ 0 ].activeElement;
188+
189+
// Support: IE9, IE10
190+
// If the <body> is blurred, IE will switch windows, see #4520
191+
if ( activeElement && activeElement.nodeName.toLowerCase() !== "body" ) {
192+
193+
// Hiding a focused element doesn't trigger blur in WebKit
194+
// so in case we have nothing to focus on, explicitly blur the active element
195+
// https://bugs.webkit.org/show_bug.cgi?id=47182
196+
$( activeElement ).blur();
197+
}
198+
} catch ( error ) {}
186199
}
187200

188201
this._hide( this.uiDialog, this.options.hide, function() {

0 commit comments

Comments
 (0)