I had to do some JS trickery to implement a preview feature by posting via AJAX without having to reload the current page.
The problem I ran into was displaying the output into an iframe.
Assuming the HTML is:
<iframe id='preview-iframe' src="about:blank"></iframe> We can use this jQuery command to inject the HTML into the iframe.
$('#preview-iframe').contents().find('html').html(data); Update (18/01/13): Thanks Nikri for the IE about:blank fix!

This worked for me, but I had to load a page into the iframe first. Othewise, there was no html object for jquery to find and then fill.
ReplyDeleteAhh good point, didn't spot that. Thanks!
ReplyDeleteSeems not to work on IE, right ?
ReplyDeleteNot sure, which version?
ReplyDeleteWorks beautifully! Thanks for this.
ReplyDeleteHi Saam,
ReplyDeleteJust place a about:blank in the source and it will work as well in IE, like so: src="about:blank"
Thanks for that Nikri, I've updated the blog to include your fix.
DeleteI used the code in the blog post plus the about:blank suggestion from Nikri and it worked great in IE9. Cheers
ReplyDeletep.s. you should accept donations in bitcoins, its the future.
I've just updated the blog to include Nikri's IE fix.
DeleteBitcoins aye? I took a look at it a while back but had no idea how it worked.
thank you panpa
ReplyDeleteYes, but "about:blank" causes Google to see a 404. Not good!
ReplyDelete