8

I have an iframe which does picture uploading to give a false sense of Ajax uploading.

This iframe's content has javascript which checks various things and sends status. See it as a progress report almost. Anyway, my page that contains the iframe, is the one showing the data and what not, so I want to change the data on the parent page, from within the iframe. Here is my code:

<div id="iframe_response"></div>
<iframe style="border:none" src="someurl" width="100%" height="350px" id="iframe"></iframe>

And here is my jQuery in the iframe:

$('#iframe_response', "#iframe").append('this should go there but it\'s not...');

It does however not write anything to that div. I have called it on document.ready, but alas...

What am I doing wrong?

Bird87 ZA
  • 2,259
  • 8
  • 33
  • 62

4 Answers4

11

use parent.document instead of window.parent.document

$(parent.document).find('#whatever')
Steven Pribilinskiy
  • 1,452
  • 15
  • 19
5

Here's the answer! It's just a little confusing to start with but really easy!

Assuming that same origin policy is not a problem, you can use parent.document to access the elements, and manipulate them.

Demo: Here
Iframe Outer: Here
Iframe Inner: Here

Hope this helps, Spent I fair bit of time figuring this out for you so I'd love the support of upping my answer!

Cheers, Shannon

Shannon
  • 562
  • 1
  • 5
  • 14
1

I had the same issue and none of the above solutions (jquery) did work for me.

After a little bit of trial and error this worked for me:

(But beware, this will only work if parent also supports Jquery)

window.parent.$('#iframe_response').html('this should go there but it\'s not...');
makim
  • 2,850
  • 2
  • 28
  • 46
0

You should try this

$(window.parent).find('#iframe_response').html('this should go there but it\'s not...');
Yograj Gupta
  • 9,638
  • 3
  • 25
  • 45