Bug Tracker

Modify

Ticket #11260 (closed bug: invalid)

Opened 17 months ago

Last modified 17 months ago

Invoking contents() on a jQuery constructed iframe causes javascript error

Reported by: ts@… Owned by:
Priority: low Milestone: None
Component: manipulation Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

  • The version affected

jquery-1.7.1.js

  • The browsers you are able to reproduce the bug in

Google Chrome 16.0.912.77 Firefox 7.0.1

  • The operating system you experienced the bug on

Debian Squeeze

  • Step-by-step instructions on how to reproduce the issue

Execute the following code, for example in the Chrome console (in a page with jQuery loaded): $("<iframe src=' http://example.com'></iframe>").contents();

  • What you expect to happen, and what actually happens

I expect the expression above to execute without generating a javascript error. What happens is that a javascript error is logged in the console. This occurs for both Firfox and Chrome.

Example of Chrome error message:

Uncaught TypeError: Cannot read property 'document' of null jQuery.each.contentsjquery-1.7.1.js:5515 jQuery.extend.mapjquery-1.7.1.js:771 jQuery.each.jQuery.fn.(anonymous function)jquery-1.7.1.js:5520 (anonymous function)

  • Information on other browsers where the issue does not occur

Only tested in Chrome and Firefox

Change History

comment:1 Changed 17 months ago by sindresorhus

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to manipulation

The iframe needs to be inserted into the body and loaded before you can get it's contents.

Something like this:  http://jsfiddle.net/mofle/M3pHT/

Also make sure it's on the same domain and subdomain.

In the future we would appreciate if you provided a testcase on jsfiddle when reporting bugs.

comment:2 Changed 17 months ago by ts@…

I am aware that this only happens if the iframe is not inserted into the body. However, I thought this is an obvious and easy to correct bug in the jQuery code, so I thought I would report it, since javascript errors are always embarrassing.

I actually did make a test case on jsfiddle, but the ticket tracker would not let me submit the bugreport, always telling me that it is spam, until I figured that it may be caused by the short jsfiddle URL and removed it. Even after I created the ticket, the issue tracker would not let me add the jsfiddle URL as a comment. However is in charge of the Issue Tracke may want to have a look at this :-).

comment:3 Changed 17 months ago by anonymous

By the way, this is not something I invented, it actually occurred in some production code I am maintaining! The code was iterating through a detached DOM tree, using contents() to get at the nodes on each level, which always failed when an iframe was encountered.

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.