Reloading an IFrame via Ajax Request in Firefox and IE

iframe-ajax-reload-header

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.


Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkArena
  • LinkedIn
  • MisterWong
  • MisterWong.DE
  • Netvibes
  • NewsVine
  • StumbleUpon
  • Technorati
  • Wykop
  • Yigg
  • BlinkList
  • email
  • MySpace
  • TwitThis

Previous & Next Post



One Response to “Reloading an IFrame via Ajax Request in Firefox and IE”


Trackbacks/Pingbacks

  1. [...] Read more: Reloading an IFrame via Ajax Request in Firefox and IE [...]

Leave a Reply