[英]Refreshing an iFrame in a Web Browser Control
C#Visual Studio 2010
我有一个复杂的网页,其中包含要加载到网络浏览器控件中的多个iframe。 当用户单击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#代码中调用此代码:
browser.Document.InvokeScript("reloadFrame", new[] { "myFrameId" });
如何使用MSHTML和IHTMLLocation接口的重载方法。 您将添加对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
则从缓存中检索页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.