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+