I needed to do some magical AJAXy previewing (inline) for an email templating system I’m building that generates both text and HTML versions of an email. For displaying the HTML version of the email inline I was using an iFrame. Using jQuery to do an AJAX post of the template, I then needed to render the response inline, and essentially wanted to just replace the HTML contents of an iFrame with the HTML response I received back from my AJAX jQuery post.
I found this tidbit from Twig’s Tech Tips, which did exactly what I wanted. Using an iFrame like this (no src attribute):
<iframe id="preview-iframe" width="320" height="240"></iframe>
You can use this jQuery call to replace the contents of the iFrame:
$('#preview-iframe').contents().find('html').html(data);



