WebBrowser.只需导航..是不是;t
本文关键字:是不是 导航 WebBrowser | 更新日期: 2023-09-27 18:26:19
我有这个代码:
private void goButton_Click(object sender, EventArgs e)
{
web.Navigate(loginURL.Text + "/auth/login");
}
我显示了浏览器,但它无法导航。。。它不能导航等
URL有效。
Navigate(Uri url)
重载。
// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address))
return;
if (address.Equals("about:blank"))
return;
if (!address.StartsWith("http://") && !address.StartsWith("https://"))
{
address = "http://" + address;
}
try
{
webBrowser.Navigate(new Uri(address));
}
catch (System.UriFormatException)
{
return;
}
}
您需要处理web浏览器的DocumentCompleted
事件。
通过以下代码:
private void goButton_Click(object sender, EventArgs e)
{
WebBrowser wb = new WebBrowser();
wb.AllowNavigation = true;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb.Navigate(loginURL.Text + "/auth/login");
}
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = sender as WebBrowser;
// wb.Document is not null at this point
}