diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-07-10 18:25:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-10 18:25:56 +0200 |
commit | 87467a6f62b5fbd820ab387836e2a6fb186cbc1b (patch) | |
tree | e514793b8d53c0521d92884584ba2d6deef4b4da /src | |
parent | 3c18c1f33cfc69e1e1bd1410ab5176b2abc5fe3a (diff) | |
download | jquery-87467a6f62b5fbd820ab387836e2a6fb186cbc1b.tar.gz jquery-87467a6f62b5fbd820ab387836e2a6fb186cbc1b.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/selector.js | 17 |
1 files changed, 11 insertions, 6 deletions
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+ |