C# 刷新Web浏览器控件中的iFrame

C# 刷新Web浏览器控件中的iFrame,c#,iframe,web-controls,C#,Iframe,Web Controls,C#Visual Studio 2010 我有一个复杂的网页,其中包含几个iFrame,我正在将它们加载到web浏览器控件中。我试图找出一种方法,当用户单击windows窗体上的按钮时,刷新其中一个iFrame 我找不到任何特定于刷新单个iframe的内容。有什么想法吗?在DOM中,您可以调用: document.getElementById([FrameID]).contentDocument.location.reload(true); 使用WebBrowser控件,您可以使用Docume

C#Visual Studio 2010

我有一个复杂的网页,其中包含几个iFrame,我正在将它们加载到web浏览器控件中。我试图找出一种方法,当用户单击windows窗体上的按钮时,刷新其中一个iFrame


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

在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#代码中调用:

如何使用和接口的方法。您可以添加对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
从缓存中检索页面。

我不太清楚这是如何工作的。我无法控制正在加载到web浏览器控件中的网页。听起来需要将reloadFrame javascript函数添加到页面中,此解决方案才能正常工作。对吗?我就是这个意思,对。我以为你可以用iframe控制页面。抱歉帮不上忙。别担心,我很感激你的想法——还有人有什么想法吗?我在第一行收到一个未经授权的访问异常。“访问被拒绝。”访问DOM的这一部分我缺少什么?我发现存在跨帧脚本安全问题。有办法解决这个问题吗?我只想重新加载帧。
IHTMLDocument2 doc = webBrowser1.Document.Window.Frames["MyIFrame"].Document.DomDocument as IHTMLDocument2;
IHTMLLocation location = doc.location as IHTMLLocation;

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