How to refresh an IFrame using Javascript?

2019-01-02 15:10发布

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.

13条回答
回忆,回不去的记忆
2楼-- · 2019-01-02 15:36

You can use this:

Js:

function refreshFrame(){
    $('#myFrame').attr('src', "http://blablab.com?v=");
}

Html:

`<iframe id="myFrame" src=""></iframe>`

JS Fiddle : https://jsfiddle.net/wpb20vzx/

查看更多
大哥的爱人
3楼-- · 2019-01-02 15:41

You can use this simple method

function reloadFrame(iFrame) {

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

}
查看更多
无与为乐者.
4楼-- · 2019-01-02 15:42

Works for IE, Mozzila, Chrome

document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);
查看更多
初与友歌
5楼-- · 2019-01-02 15:43

Got this from here

var f = document.getElementById('iframe1');
f.src = f.src;
查看更多
浮光初槿花落
6楼-- · 2019-01-02 15:43

2017:

If it in on same domain just :

iframe.contentWindow.location.reload();

will work.

查看更多
柔情千种
7楼-- · 2019-01-02 15:47

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

iframe.contentWindow.location.reload();
查看更多
登录 后发表回答