How to refresh an IFrame using Javascript?

How to refresh an IFrame using Javascript?

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.

Solutions/Answers:

Solution 1:

var iframe = document.getElementById('youriframe');
iframe.src = iframe.src;

Solution 2:

This should help:

document.getElementById('FrameID').contentWindow.location.reload(true);

EDIT: Fixed the object name as per @Joro’s comment.

Solution 3:

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

iframe.contentWindow.location.reload();

Solution 4:

Works for IE, Mozzila, Chrome

document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);

Solution 5:

You can use this simple method

function reloadFrame(iFrame) {

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

}

Solution 6:

Got this from here

var f = document.getElementById('iframe1');
f.src = f.src;