[英]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.