Dantès Cristo
Dantès Cristo

Reputation: 183

Refresh current page in iframe with javascript/jquery

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!

Upvotes: 0

Views: 1949

Answers (1)

chirag
chirag

Reputation: 1828

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.

Upvotes: 3

Related Questions