0

可能重复:
如何在 C# 中使用 WebBrowser 控件 DocumentCompleted 事件?

有人可以告诉我为什么 DocumentCompleted 事件发生 3 次???

我怎么知道该文件真的已经被下载了?

(我用一些页面来测试有很多 jQuery。)

谢谢!

var webBrowser1 = new WebBrowser
                {
                    Padding = new Padding(0),
                    Margin = new Padding(0),
                    Dock = DockStyle.Fill,
                    Url = url,
                    TabStop = false,
                    ScriptErrorsSuppressed = true,
                    IsWebBrowserContextMenuEnabled = false
                };
                webBrowser1.Navigated +=  (d1,d2) => 
                {
                    Debug.WriteLine("Navigated " + DateTime.Now.TimeOfDay.ToString());
                };
                webBrowser1.DocumentCompleted += (d1, d2) => 
                {
                    Debug.WriteLine("DocumentCompleted " + DateTime.Now.TimeOfDay.ToString());                
                };


                form.Controls.Add(webBrowser1);
                form.Show();

日志:

导航09:40:40.1807403导航09:40:44.7270004 documentCompleted 09:40:44.7300005导航09:40:40:46.5791063 documentCompemed Commpleted 09:40:40:40:40:46.5821065 Naimbiged 09:40.40.40.40.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111卡库蒂克

4

1 回答 1

0

我在这里找到了一个好方法

如何在 C# 中使用 WebBrowser 控件 DocumentCompleted 事件?

 webBrowser1.DocumentCompleted += (d1, d2) => 
                {


                    string urlCurrent = d2.Url.ToString();
                    var browser = (WebBrowser)d1;

                    if (!(urlCurrent.StartsWith("http://") || urlCurrent.StartsWith("https://")))
                    {
                        // in AJAX     
                    }
                    if (d2.Url.AbsolutePath != browser.Url.AbsolutePath)
                    {
                        // IFRAME           
                    }
                    else
                    {
                        // REAL DOCUMENT COMPLETE

                        Debug.WriteLine("DocumentCompleted " + DateTime.Now.TimeOfDay.ToString());
                    }

                };
于 2012-08-28T13:00:16.137 回答