Manipulate main frame from iFrame with jQuery?

I'm tricking iFrames a bit to give the illusion of AJAX loading. When the download is complete, I need to report information about the file that was loaded in the main frame and list it.

If I have the following UL in the main frame and a JS variable in an iFrame named filename, how can I add filename to the list?

<ul id="uploaded_files">
  <li>My_file_name.jpg</li>
</ul>

      

+2


source to share


1 answer


Depending on where jQuery is loaded:

// jQuery is in the parent window
parent.$('#uploaded_files').append('<li/>').text(filename);

      



or

// jQuery is in the iframe
$('#uploaded_files', parent).append('<li/>').text(filename);

      

+9


source







All Articles