Skip to main content

Bug Tracker

Side navigation

#11275 closed bug (invalid)

Opened February 02, 2012 11:18PM UTC

Closed February 02, 2012 11:50PM UTC

Last modified February 03, 2012 01:36AM UTC

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

Reported by: bob@poekert.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description
 $(document.createElement('iframe')).contents(); 

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

Attachments (0)
Change History (4)

Changed February 02, 2012 11:50PM UTC by rwaldron comment:1

resolution: → invalid
status: newclosed

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

Changed February 03, 2012 01:25AM UTC by anonymous comment:2

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.

Changed February 03, 2012 01:29AM UTC by dmethvin comment:3

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

Changed February 03, 2012 01:36AM UTC by anonymous comment:4

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.