From: Michał Gołębiowski-Owczarek Date: Mon, 10 Jul 2023 16:25:56 +0000 (+0200) Subject: Selector: Only attach the unload handler in IE & Edge Legacy X-Git-Tag: 3.7.1~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87467a6f62b5fbd820ab387836e2a6fb186cbc1b;p=jquery.git 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 gh-5281 Closes gh-5282 Ref gh-4792 --- diff --git a/src/selector.js b/src/selector.js index 924846ff6..706a7f1e9 100644 --- a/src/selector.js +++ b/src/selector.js @@ -523,12 +523,17 @@ function setDocument( node ) { documentElement.msMatchesSelector; // Support: IE 9 - 11+, Edge 12 - 18+ - // Accessing iframe documents after unload throws "permission denied" errors (see trac-13936) - // Support: IE 11+, Edge 17 - 18+ - // IE/Edge sometimes throw a "Permission denied" error when strict-comparing - // two documents; shallow comparisons work. - // eslint-disable-next-line eqeqeq - if ( preferredDoc != document && + // Accessing iframe documents after unload throws "permission denied" errors + // (see trac-13936). + // Limit the fix to IE & Edge Legacy; despite Edge 15+ implementing `matches`, + // all IE 9+ and Edge Legacy versions implement `msMatchesSelector` as well. + if ( documentElement.msMatchesSelector && + + // Support: IE 11+, Edge 17 - 18+ + // IE/Edge sometimes throw a "Permission denied" error when strict-comparing + // two documents; shallow comparisons work. + // eslint-disable-next-line eqeqeq + preferredDoc != document && ( subWindow = document.defaultView ) && subWindow.top !== subWindow ) { // Support: IE 9 - 11+, Edge 12 - 18+