Skip to content

Commit 88d092a

Browse files
committed
Selector: Only attach the unload handler in IE & Edge Legacy
Both IE & Edge Legacy need the workaround of calling `setDocument()` in an `unload` handler to avoid "permission denied" errors. However, due to not being possible to feature-detect this issue, the handler has been applied in all browsers for windows different than the one in which jQuery was loaded. jQuery 4.0, which drops Edge Legacy support, guards this workaround with a `document.documentMode` check. This won't work in the 3.x line due to still supporting Edge Legacy but we can check for `document.documentElement.msMatchesSelector` instead as that API is supported in IE 9+ and all Edge Legacy versions. Fixes jquerygh-5281 Ref jquerygh-4792
1 parent 4a29888 commit 88d092a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/selector.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,17 @@ function setDocument( node ) {
523523
documentElement.msMatchesSelector;
524524

525525
// Support: IE 9 - 11+, Edge 12 - 18+
526-
// Accessing iframe documents after unload throws "permission denied" errors (see trac-13936)
527-
// Support: IE 11+, Edge 17 - 18+
528-
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
529-
// two documents; shallow comparisons work.
530-
// eslint-disable-next-line eqeqeq
531-
if ( preferredDoc != document &&
526+
// Accessing iframe documents after unload throws "permission denied" errors
527+
// (see trac-13936).
528+
// Limit the fix to IE & Edge Legacy; despite Edge 15+ implementing `matches`,
529+
// all IE 9+ and Edge Legacy versions implement `msMatchesSelector` as well.
530+
if ( documentElement.msMatchesSelector &&
531+
532+
// Support: IE 11+, Edge 17 - 18+
533+
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
534+
// two documents; shallow comparisons work.
535+
// eslint-disable-next-line eqeqeq
536+
preferredDoc != document &&
532537
( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {
533538

534539
// Support: IE 9 - 11+, Edge 12 - 18+

0 commit comments

Comments
 (0)