Bug Tracker

Modify

Ticket #11275 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

$.fn.contents fails when passed an iframe that isn't in the main dom tree

Reported by: bob@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

$(document.createElement('iframe')).contents();

Throws an exception when trying to access contentDocument on the iframe tag, which doesn't exist.

Change History

comment:1 Changed 2 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to invalid

iframe's won't have a content window until they are attached to the dom

comment:2 Changed 2 years ago by anonymous

The bug isn't that contentDocument doesn't exist, but that jQuery always expects it to. The correct behavior would be to return no elements or to return node.children (which will most likely be an empty array), not to throw an exception.

comment:3 Changed 2 years ago by dmethvin

Does it make sense to do that? Seems like it's just masking the problem. Do you have a real-life use case?

comment:4 Changed 2 years ago by anonymous

I'm writing a Radability clone that runs on the client, which transforms an arbitrary document before the browser renders it, and there are some transformations that I do on all of the text nodes rooted at a given node.

The way I initially tried to do that was:

$my_node.find('*').contents().each(function() {
    // do stuff
});

But whenever the subtree rooted at $my_node contained an iframe I would get an exception at an arbitrary point. I'm hacking around it by doing:

$my_node.find(':not(iframe)').contents().each(function() {
    /* do stuff */ 
}); 

but that feels wrong.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.