Advertisement
Advertisement


How to refresh an IFrame using Javascript?


Question

I have a webpage with an IFrame and a Button, once the button is pressed I need the IFrame to be refreshed. Is this possible, if so how? I searched and could not find any answers.

2010/01/14
1
122
1/14/2010 2:42:33 PM

Accepted Answer

var iframe = document.getElementById('youriframe');
iframe.src = iframe.src;
2010/01/14
153
1/14/2010 2:45:13 PM


provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:

iframe.contentWindow.location.reload();
2018/11/22

Works for IE, Mozzila, Chrome

document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);
2014/01/13

You can use this simple method

function reloadFrame(iFrame) {

    iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

}

Got this from here

var f = document.getElementById('iframe1');
f.src = f.src;
2010/01/14

2017:

If it in on same domain just :

iframe.contentWindow.location.reload();

will work.

2017/11/20

Source: https://stackoverflow.com/questions/2064850
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]