Reloading an IFrame via Ajax Request in Firefox and IE

Recently I was working on a web project where I needed to show a preview window which was basically an IFrame. As the whole page navigation was based on Ajax calls I was looking for a bulletproof method for reloading an IFrame.
The first solution (only Firefox)
IFrame code:
Ajax code:
var iframe = document.getElementById("preview_content");
iframe.contentDocument.location.reload(true);
Well, this solution was working quite nice with Firefox but IE wouldn’t reload the page at all.
The proper solution
Ajax code:
var iframe = document.getElementById("preview_content");
iframe.src = "preview.php?x="+Math.round(Math.random());
The additional parameter x (a random number) will cause IE to reload the IFrame properly without using the cache.
Leave a Reply

One Response to “Reloading an IFrame via Ajax Request in Firefox and IE”
Trackbacks/Pingbacks
[...] Read more: Reloading an IFrame via Ajax Request in Firefox and IE [...]