简体   繁体   English

如何让webBrowser_Documentcompleted多次触发

[英]How to let the webBrowser_Documentcompleted fire multiple times

I made a simple webbrowser in c#, which keeps reloading a page and then does something when the page is loaded. 我用c#创建了一个简单的Web浏览器,该浏览器不断重新加载页面,然后在加载页面时执行一些操作。

However, after the first time, the following function doesn't fire anymore: 但是,第一次之后,以下函数将不再触发:

public void gotourl()
{
   webBrowser.Navigate("Stackoverflow.com");
}

 public void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
   MessageBox.Show("Page loaded succesfully."); // only fires once
   // waiting for a few seconds by using a timer
   gotourl();
}

However, I did reload the page. 但是,我确实重新加载了页面。 The documentcompleted state simply doesn't fire again. documentcomplete状态完全不会再次触发。

Is there a way to let the function fire every time I navigate to an url? 有没有办法让该函数在每次导航到URL时触发?

( I also tried webBrowser.Refresh() ) (我也尝试过webBrowser.Refresh())

EDIT: I added the unbelievable solution.. 编辑:我添加了令人难以置信的解决方案。

The solution is unbelievable. 该解决方案令人难以置信。 After hours of searching and trying things, I found the answer. 经过数小时的搜索和尝试,我找到了答案。

In the properties of webBrowser1, I set the property "AllowNavigation" to false. 在webBrowser1的属性中,我将属性“ AllowNavigation”设置为false。

If set to false, it only registers the webBrowser1.DocumentCompleted() function only ONCE, but when the AllowNavigation property is set to true(which it is by default), the DocumentCompleted() function repeats. 如果设置为false,则仅一次注册webBrowser1.DocumentCompleted()函数,但是当AllowNavigation属性设置为true(默认情况下为true)时,将重复DocumentCompleted()函数。

I have no clue why it works this way and I hope people with the same problem find this answer, as it is the only answer on the net.. 我不知道为什么会这样,我希望有同样问题的人找到这个答案,因为它是网络上唯一的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM