刷新Web浏览器控件中的iFrame

时间:2010-08-12 23:59:03

标签: c# iframe web-controls

C#Visual Studio 2010

我有一个复杂的网页,其中包含我加载到网络浏览器控件中的几个iframe。当用户点击Windows窗体上的按钮时,我正试图找出一种方法来刷新其中一个iframe。

我找不到任何特定于刷新单个iframe的内容。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

在DOM中,您可以调用:

document.getElementById([FrameID]).contentDocument.location.reload(true);

使用WebBrowser控件,您可以使用Document的InvokeScript方法自己执行javascript:

browser.Document.InvokeScript([FunctionName], [Parameters]);

通过在父页面中编写自己的函数将这两个概念放在一起:

function reloadFrame(frameId) {
    document.getElementById(frameId).contentDocument.location.reload(true);
}

并在您的C#代码中调用它:

browser.Document.InvokeScript("reloadFrame", new[] { "myFrameId" });

答案 1 :(得分:1)

如何使用MSHTML接口的reloadIHTMLLocation方法。您将添加对Microsoft.mshtml的引用,然后尝试:

IHTMLDocument2 doc = webBrowser1.Document.Window.Frames["MyIFrame"].Document.DomDocument as IHTMLDocument2;
IHTMLLocation location = doc.location as IHTMLLocation;

if (location != null)
    location.reload(true);

true从服务器重新加载页面,而false从缓存中检索它。