Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11275 closed bug (invalid)

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

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:



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

Change History (4)

comment:1 Changed 11 years ago by Rick Waldron

Resolution: invalid
Status: newclosed

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

comment:2 Changed 11 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 11 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 11 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.

Note: See TracTickets for help on using tickets.