Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

[JavaScript] How to Reload iFrame – Works in FF, Crome, IE, Safari

Hello Friends,

I was working with one web application and I placed a iFrame in it. I am making ajax call and updating iFrame files. Now I want to refresh only iFrame. I found many solution via Google and I tried many with my own idea to replace iFrame or load iFrame etc etc. But none of them works in all browsers including IE. Some of them are working in FF, some of them in other browsers. I was looking for a solution which works in all browsers. Finally I found the one which works in all browsers.

:: Works in FF, IE, Crome, Safari ::

document.getElementById("ifr").contentWindow.location.reload(true);

:: Not Working ::

document.getElementById("ifr").contentDocument.location.reload(true);
var fr = document.getElementById("ifr");
if(fr!=null) 
	document.getElementById("previewiframe").removeChild(fr);
var iframehtml = '<iframe id="ifr" style="z-index: -1; margin: auto; text-align: center; padding: 0 0 0 20px; border: none;" src="demo/index.php" height="453" width="300"></iframe>';
document.getElementById("previewiframe").innerHTML = iframehtml;

Just changing contentDocument.location.reload() to contentWindow.location.reload() works fine in all browsers. It has problem in IE. iFrame reload was not working in IE but with the first code, it works in IE also. IE iFrame reloads resolved.

Share:

1 Comment

  • Jeff

    Hi ,

    i working in .phtml of index controller (zend)
    i need to src a java script but i am unable to do so
    swfobject.js
    code is
    headScript()->appendFile($this->baseUrl() . ‘/public/video/swfobject.js’);?>

    it says undefine object

    i think it is not find the .js path
    how can we reference in index.phtml the js script using the php

    i tried something i saw on this website but it is not working

Leave a Reply

Your email address will not be published.