Reload iframe src / location with new url not working in Safari

So the answer is very simple:
1. put a <div id="container"> </div> on your page
2. when reload needed use following jQuery:

$("#container").empty();
$("#container").append("<iframe src='" + url + "' />");

and that's it. Of course there is more elegant way of creating DOM with jQuery but this gives the idea of "refreshing" iframe. Works in FF18, CH24, IE9, O12 (well it's jQuery so it will work almost always :)


Some browsers don't use "src" when calling the javascript object directly from the javascript hierarchy and others use "location" or "href" instead of "src" to change the url . You should try these two methods to update your iframe with a new url.

To prevent browser cache add a pseudo-random string like a number and timestamp to the url to prevent caching. For example add "new Date().getTime()" to your url.

Some calling examples:

document.getElementById(iframeId).src = url;

or

window.frames[iframeName].location = url;  

I recommend the first option using document.getElementById

Also you can force the iframe to reload a page using

document.getElementById(iframeId).reload(true);

I found a better solution (albeit not paticularly eloquent) for this using jQuery.ajax:

jQuery.ajax({
   type: 'GET',
   url: "/somePage?someparms",
   success: function() {
      frameObj.src = "/somePage?someparms";
   }
});

This forces the DOM to be read within the frame object, and reloads it once the server is ready to respond.