Bug Tracker

Modify

Ticket #9605 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

Trouble with IE6 and the $('html') function with iframes

Reported by: songofchrist@… Owned by:
Priority: low Milestone: 1.next
Component: manipulation Version: 1.6.1
Keywords: neededdocs Cc:
Blocking: Blocked by:

Description

I am trying to create html using the $() function and then insert this into the body of an iframe. It works fine on firefox and chrome, but messes up in IE6 (naturally). Here's what the code looks like:

$('#myiframe').contents().find('body').html($('<div>myhtml</div>').css({...}));

IE6 gives the error "invalid argument" whenever the div is surrounded by $(). If I remove the $(), it works fine. There's definitely a workaround for this, but it seems like something that ought to work but doesn't.

Change History

comment:1 Changed 3 years ago by timmywil

  • Priority changed from undecided to low
  • Component changed from unfiled to manipulation

The docs do not show a jQuery object as a valid argument for html.  http://api.jquery.com/html/ However, maybe they should?

comment:2 Changed 3 years ago by timmywil

  • Keywords needsreview added

comment:3 Changed 3 years ago by addyosmani

  • Keywords needsdocs added; needsreview removed
  • Status changed from new to closed
  • Resolution set to invalid

Thanks for submitting a ticket to the jQuery project. I've just tested your ticket out here:  http://jsfiddle.net/wLxne/1/ across IE6, 7, 8 and 9 and the main problem with IE appears to be permission/security issues when attempting to modify the contents of the iframe most likely due to cross-site scripting. This is consistant with the errors experienced when attempting to modify the contents of the iframe body (in the same browsers) where the parameters passed to .html() are plain-text or inline HTML as a string.

As per the jsfiddle, .html() does in-fact support jQuery objects so I'll add a needsdocs tag to ensure this is addressed.

comment:4 Changed 3 years ago by dmethvin

IE has significant restrictions in moving DOM nodes from one document to another document (iframe). You can inject new content into the iframe using .innerHTML though. Because of the limits of older IE this isn't something jQuery can support across browsers. Here is some more painful detail:

 http://www.alistapart.com/articles/crossbrowserscripting/

comment:5 Changed 3 years ago by addyosmani

  • Keywords neededdocs added; needsdocs removed

From Dave, Karl and I's discussions regarding this particular ticket (and a correction to my earlier response):

The reason the OP had the problem is that $("html") creates the elements in the current document, and then they were trying to tack them onto a different document in an iframe. IE doesn't allow that.

So the take on this is that there is nothing we need to do, unless we want to document that all content-changing operations (.append, .appendTo, etc.) don't work in IE when you try to put the content in a different document. We however think it's too much of an edge case to clutter the docs everywhere.

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.