]> source.dussan.org Git - jquery.git/commitdiff
Traversing: Fix `contents()` on `<object>`s with children
authorPat O'Callaghan <patocallaghan@gmail.com>
Mon, 6 May 2019 17:23:00 +0000 (18:23 +0100)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 6 May 2019 19:07:53 +0000 (21:07 +0200)
(cherry-picked from 4d865d96aa5aae91823c50020b5c19da79566811)

Fixes gh-4384
Closes gh-4385

src/traversing.js
test/unit/traversing.js

index 426d5b6ea31696733f771250087951c5e6b6fb05..25843ee8c744230f47744494c6cb1ab3dfa07b5e 100644 (file)
@@ -145,7 +145,7 @@ jQuery.each( {
                return siblings( elem.firstChild );
        },
        contents: function( elem ) {
-               if ( typeof elem.contentDocument !== "undefined" ) {
+               if ( elem.contentDocument != null ) {
                        return elem.contentDocument;
                }
 
index e70c121edf8e8d99c90dd6d826e28aaecd91acfa..e8d23536ef955e3aaafb3b47a3795ca07a640cdc 100644 (file)
@@ -808,6 +808,19 @@ QUnit.test( "contents() for <object />", function( assert ) {
        jQuery( "#qunit-fixture" ).append( svgObject );
 } );
 
+QUnit.test( "contents() for <object /> with children", function( assert ) {
+       assert.expect( 1 );
+
+       var object = "<object type='application/x-shockwave-flash' width='200' height='300' id='penguin'>" +
+               "<param name='movie' value='flash/penguin.swf'>" +
+               "<param name='quality' value='high'>" +
+               "<img src='images/penguin.jpg' width='200' height='300' alt='Penguin'>" +
+       "</object>";
+
+       var contents = jQuery( object ).contents();
+       assert.equal( contents.length, 3, "Check object contents children are correct" );
+} );
+
 QUnit.test( "contents() for <frame />", function( assert ) {
        assert.expect( 2 );