0

I have an offline HTML file, on which I am working with iframes. I was wondering if there is a way to refresh the page from the iframe clicking on a button? The current page is on the home page domain. I would need to reload the current page. This is what I have so far http://jsfiddle.net/3jkbadr3/1/ I just entered a generic iframe address (jsfiddle home page), which opens in iframe, for testing.

<div class="iframe_box">
    <iframe id="iframe1" frameborder="0" name="iframe1" src="http://jsfiddle.net/"></iframe>
</div>
<div class="menu">
    <div class="button-wrapper">
        <button id="refresh_btn" title="Refresh Current Page" onclick="resetIframe1();">Home Page</button>
    </div>
</div>

Thanks!

Dantès Cristo
  • 183
  • 3
  • 15
  • 1
    possible duplicate of [How to refresh an IFrame using Javascript?](http://stackoverflow.com/questions/2064850/how-to-refresh-an-iframe-using-javascript) – Dan Smith Mar 12 '15 at 12:34
  • @Dantes Cristo : If you get your answer then accept answer. – chirag Mar 12 '15 at 13:17
  • I just checked that thread, however it just does not work with Chrome. Instead of refreshing current page, it reloads the original page. – Dantès Cristo Mar 12 '15 at 13:31
  • @chirag Should I accept the duplicate and continue working in the duplicate? – Dantès Cristo Mar 12 '15 at 13:55
  • 1
    you can find more info here [link](http://stackoverflow.com/questions/14217813/javascript-refresh-iframe-browser-specific) – chirag Mar 12 '15 at 14:06
  • @chirag It seems it is not responsive http://jsfiddle.net/3jkbadr3/2/ could you please take a look at this? – Dantès Cristo Mar 12 '15 at 14:16
  • 1
    I have ran this code and i get this error "Permission denied to access property 'reload'". and why we get this error beacuse of “Same Origin” policy limits the access of one window to another.the reason behind that is security. You can refer http://jsfiddle.net/zchirag50/k921ek34/. I changed src of iframe and it is working fine. – chirag Mar 13 '15 at 05:06

1 Answers1

3

You can try this.

document.getElementById('iframe1').contentWindow.location.reload();

Used above line and it gives error sometime, because it is not allowed to get a property from the window from another domain.

The “Same Origin” policy limits the access of one window to another.

The reason behind that is security. If you have blabla.com in one window and gmail.com in another one, then you’d not want a script from blabla.com to access or modify your mail or run actions in context of gmail on your behalf.

You can refer http://javascript.info/tutorial/same-origin-security-policy more information.

chirag
  • 1,818
  • 1
  • 15
  • 36
  • For some reason, it does not work. I defined a new function and included your code in it, recalled it using onclick and nothing happens. – Dantès Cristo Mar 12 '15 at 13:22