Skip to content


Subversion checkout URL

You can clone with
Download ZIP


contents() on iframes does return iframe contents #821

tpae opened this Issue · 5 comments

5 participants



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:

Here's a quick fiddle with jQuery:


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

return { return this.contentDocument || })
@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

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


Sorry this had gone unaddressed.

Does anyone care to submit a PR?

@mislav mislav added the Bug label

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).


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")
  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.