]> source.dussan.org Git - jquery.git/commitdiff
Traversing: Fix `contents()` on `<object>`s with children in IE
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Wed, 8 May 2019 08:12:36 +0000 (10:12 +0200)
committerGitHub <noreply@github.com>
Wed, 8 May 2019 08:12:36 +0000 (10:12 +0200)
The original fix didn't account for the fact that in IE `<object>` elements
with no `data` attribute have an object `contentDocument`. The fix leverages
the fact that this special object has a null prototype.

Closes gh-4390
Ref gh-4384
Ref gh-4385

src/traversing.js

index a91183b289d27fa7b3655696b64d4d212b498258..72530ed85e7c77b5452b2106733398e069f1f27b 100644 (file)
@@ -1,5 +1,6 @@
 define( [
        "./core",
+       "./var/getProto",
        "./var/indexOf",
        "./traversing/var/dir",
        "./traversing/var/siblings",
@@ -9,7 +10,7 @@ define( [
        "./core/init",
        "./traversing/findFilter",
        "./selector"
-], function( jQuery, indexOf, dir, siblings, rneedsContext, nodeName ) {
+], function( jQuery, getProto, indexOf, dir, siblings, rneedsContext, nodeName ) {
 
 "use strict";
 
@@ -145,7 +146,13 @@ jQuery.each( {
                return siblings( elem.firstChild );
        },
        contents: function( elem ) {
-               if ( elem.contentDocument != null ) {
+               if ( elem.contentDocument != null &&
+
+                       // Support: IE 11+
+                       // <object> elements with no `data` attribute has an object
+                       // `contentDocument` with a `null` prototype.
+                       getProto( elem.contentDocument ) ) {
+
                        return elem.contentDocument;
                }