刷新 Web 浏览器控件中的 iFrame

发布于 2024-09-14 07:22:02 字数 163 浏览 2 评论 0原文

C# Visual Studio 2010

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

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

C# Visual Studio 2010

I have a complex webpage that contains several iframes that I am loading into a web browser control. I'm trying to figure out a way to refresh one of the iframes when a user clicks a button on the windows form.

I can't find anything specific to refreshing a single iframe. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2024-09-21 07:22:02

从 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" });

From within the DOM, you can just invoke:

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

Using the WebBrowser control, you can execute javascript yourself, by using the InvokeScript method of Document:

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

Put these two concepts together by writing your own function in the parent page:

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

And invoke this in your C# code:

browser.Document.InvokeScript("reloadFrame", new[] { "myFrameId" });
哑剧 2024-09-21 07:22:02

如何使用 MSHTML 和 < reload 方法“http://msdn.microsoft.com/en-us/library/aa703641(VS.85).aspx”rel="nofollow noreferrer">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 从缓存中检索页面。

How about using MSHTML and the reload method of the IHTMLLocation interface. You would add a reference to Microsoft.mshtml then try:

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

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

A value of true reloads the page from the server, while false retrieves it from the cache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文