2013-08-05 27 views
0

我有這樣的代碼:WebBrowser.Navigate只是......是不是

private void goButton_Click(object sender, EventArgs e) 
{ 
    web.Navigate(loginURL.Text + "/auth/login"); 
} 

我的瀏覽器顯示,它只是沒有導航......它並不導航等

該網址有效。

+1

它的確如此。需要更多信息來幫助你。 –

+0

這是Windows窗體? –

+0

@alexw是的。 – Minicl55

回答

1

MSDN是你的朋友。確保你有'http://'前綴並嘗試使用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; 
    } 
} 
1

您需要處理網頁瀏覽器的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 
    } 
+1

這與這個問題有什麼關係? OP說它不是導航..而你的答案顯示了一旦導航後該怎麼做.. –

+0

@SimonWhitehead nope,op使用錯誤的導航方式] –