Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

contents() on iframes does return iframe contents #821

Closed
tpae opened this Issue · 5 comments

5 participants

@tpae

Hello,

When running contents() on iframe in jQuery, it returns all iframe contents.

When running contents() in Zepto, does not return anything.

Here's a quick fiddle with Zepto: http://jsfiddle.net/Hd97n/4/

Here's a quick fiddle with jQuery: http://jsfiddle.net/Hd97n/5/

@charsleysa

Simple fix should be to change the $.fn.contents function to the following:

return this.map(function() { return this.contentDocument || slice.call(this.childNodes) })
@woollybogger woollybogger referenced this issue from a commit in woollybogger/Firebolt
@woollybogger woollybogger Fixed bug when calling .contents() on iframes
Details in Zepto bug report: madrobby/zepto#821
22540f7
@CarsonBanov

:cactus: :+1: Are there any plans to fix this?

@mislav
Collaborator

Sorry this had gone unaddressed.

Does anyone care to submit a PR?

@mislav mislav added the Bug label
@CarsonBanov

fwiw, the example suggested by @charsleysa definitely fixed the issue (on chrome at least). For IE7< support x.contentWindow || x.contentDocument is required (although not for zepto obviously).

@altbdoor

Hi @mislav, @CarsonBanov

I can't figure out how to properly test if it is working. For now, this is what I have in mind.

testIframeContents: function(t){
  var el = $("#contentsIframeTest")
  el.contents().find("html").text("foo")
  t.assertEqual("foo", el.contents().find("html").text())
},

Is it reliable enough for a test?

I have settled with the default test for iframes so that it plays nice with other iframe tests.

testIframeContents: function(t){
  var el = $("#contentsIframeTest")
  t.assertEqual("Hello from iframe!", el.contents().find("b").first().text())
},
@altbdoor altbdoor referenced this issue from a commit in altbdoor/zepto
@altbdoor altbdoor return contentDocument on iframe contents #821 76ab3ce
@mislav mislav closed this in f2a4b6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.