可能重复:
How to use WebBrowser control DocumentCompleted event in C#?
有人能告诉我为什么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();
LOG:
导航09:40:40.1807403 导航09:40:44.7270004 DocumentCompleted 09:40:44.7300005 导航09:40:46.5791063 DocumentCompleted 09:40:46.5821065 导航09:40:50.1113083 DocumentCompleted 09:40:50.7133428 DocumentCompleted 09:40:50.7233433
答案 0 :(得分:0)
我在这里找到了一个好方法
How to use WebBrowser control DocumentCompleted event in C#?
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());
}
};