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
This commit is contained in:
Michał Gołębiowski-Owczarek 2023-07-10 18:25:56 +02:00 committed by GitHub
parent 3c18c1f33c
commit 87467a6f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
// 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
if ( preferredDoc != document &&
preferredDoc != document &&
( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {
// Support: IE 9 - 11+, Edge 12 - 18+