Redigera

Dela via


WebBrowser.Navigate Method

Definition

Loads the document at the specified location into the WebBrowser control.

Overloads

Navigate(Uri, String, Byte[], String)

Loads the document at the location indicated by the specified Uri into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

Navigate(String, String, Byte[], String)

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

Navigate(Uri, Boolean)

Loads the document at the location indicated by the specified Uri into a new browser window or into the WebBrowser control.

Navigate(Uri, String)

Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

Navigate(String, Boolean)

Loads the document at the specified Uniform Resource Locator (URL) into a new browser window or into the WebBrowser control.

Navigate(String, String)

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

Navigate(Uri)

Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the previous document.

Navigate(String)

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the previous document.

Navigate(Uri, String, Byte[], String)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the location indicated by the specified Uri into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(Uri ^ url, System::String ^ targetFrameName, cli::array <System::Byte> ^ postData, System::String ^ additionalHeaders);
public void Navigate (Uri url, string targetFrameName, byte[] postData, string additionalHeaders);
public void Navigate (Uri? url, string? targetFrameName, byte[]? postData, string? additionalHeaders);
member this.Navigate : Uri * string * byte[] * string -> unit
Public Sub Navigate (url As Uri, targetFrameName As String, postData As Byte(), additionalHeaders As String)

Parameters

url
Uri

A Uri representing the URL of the document to load.

targetFrameName
String

The name of the frame in which to load the document.

postData
Byte[]

HTTP POST data such as form data.

additionalHeaders
String

HTTP headers to add to the default headers.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

The url parameter value does not represent an absolute URI. For more information, see IsAbsoluteUri.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

See also

Applies to

Navigate(String, String, Byte[], String)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, requesting it using the specified HTTP data and replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(System::String ^ urlString, System::String ^ targetFrameName, cli::array <System::Byte> ^ postData, System::String ^ additionalHeaders);
public void Navigate (string urlString, string targetFrameName, byte[] postData, string additionalHeaders);
public void Navigate (string urlString, string? targetFrameName, byte[]? postData, string? additionalHeaders);
member this.Navigate : string * string * byte[] * string -> unit
Public Sub Navigate (urlString As String, targetFrameName As String, postData As Byte(), additionalHeaders As String)

Parameters

urlString
String

The URL of the document to load.

targetFrameName
String

The name of the frame in which to load the document.

postData
Byte[]

HTTP POST data such as form data.

additionalHeaders
String

HTTP headers to add to the default headers.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

See also

Applies to

Navigate(Uri, Boolean)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the location indicated by the specified Uri into a new browser window or into the WebBrowser control.

public:
 void Navigate(Uri ^ url, bool newWindow);
public void Navigate (Uri url, bool newWindow);
public void Navigate (Uri? url, bool newWindow);
member this.Navigate : Uri * bool -> unit
Public Sub Navigate (url As Uri, newWindow As Boolean)

Parameters

url
Uri

A Uri representing the URL of the document to load.

newWindow
Boolean

true to load the document into a new browser window; false to load the document into the WebBrowser control.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

The url parameter value does not represent an absolute URI. For more information, see IsAbsoluteUri.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload with a newWindow parameter value of false, the control navigates to the specified URI normally and adds the URI to the end of the history list. When you call this overload with a newWindow parameter value of true, the WebBrowser control loads the document at the specified URI into a new Internet Explorer window, which maintains its own navigation history. You can handle the NewWindow event to receive notification before a new browser window is opened, allowing you to cancel the action if necessary.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page or loads a page into a separate browser window, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version. When a page is loaded into a separate Internet Explorer window, the user can retrieve the latest version by clicking the Refresh button.

See also

Applies to

Navigate(Uri, String)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(Uri ^ url, System::String ^ targetFrameName);
public void Navigate (Uri url, string targetFrameName);
public void Navigate (Uri? url, string? targetFrameName);
member this.Navigate : Uri * string -> unit
Public Sub Navigate (url As Uri, targetFrameName As String)

Parameters

url
Uri

A Uri representing the URL of the document to load.

targetFrameName
String

The name of the frame in which to load the document.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

The url parameter value does not represent an absolute URI. For more information, see IsAbsoluteUri.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

See also

Applies to

Navigate(String, Boolean)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the specified Uniform Resource Locator (URL) into a new browser window or into the WebBrowser control.

public:
 void Navigate(System::String ^ urlString, bool newWindow);
public void Navigate (string urlString, bool newWindow);
member this.Navigate : string * bool -> unit
Public Sub Navigate (urlString As String, newWindow As Boolean)

Parameters

urlString
String

The URL of the document to load.

newWindow
Boolean

true to load the document into a new browser window; false to load the document into the WebBrowser control.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload with a newWindow parameter value of false, the control navigates to the specified URI normally and adds the URI to the end of the history list. When you call this overload with a newWindow parameter value of true, the WebBrowser control loads the document at the specified URI into a new Internet Explorer window, which maintains its own navigation history. You can handle the NewWindow event to receive notification before a new browser window is opened, allowing you to cancel the action if necessary.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page or loads a page into a separate browser window, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version. When a page is loaded into a separate Internet Explorer window, the user can retrieve the latest version by clicking the Refresh button.

See also

Applies to

Navigate(String, String)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the contents of the Web page frame with the specified name.

public:
 void Navigate(System::String ^ urlString, System::String ^ targetFrameName);
public void Navigate (string urlString, string targetFrameName);
public void Navigate (string urlString, string? targetFrameName);
member this.Navigate : string * string -> unit
Public Sub Navigate (urlString As String, targetFrameName As String)

Parameters

urlString
String

The URL of the document to load.

targetFrameName
String

The name of the frame in which to load the document.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control loads the document at the specified URI into the Web page frame with the specified name, and adds the URI to the end of the history list. If the frame name specified is invalid, the document is loaded into a new Internet Explorer window.

Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

See also

Applies to

Navigate(Uri)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the location indicated by the specified Uri into the WebBrowser control, replacing the previous document.

public:
 void Navigate(Uri ^ url);
public void Navigate (Uri url);
public void Navigate (Uri? url);
member this.Navigate : Uri -> unit
Public Sub Navigate (url As Uri)

Parameters

url
Uri

A Uri representing the URL of the document to load.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

The url parameter value does not represent an absolute URI. For more information, see IsAbsoluteUri.

Examples

The following code example demonstrates how to use the Navigate method to implement an address bar for the WebBrowser control. This example requires that your form contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.

For the complete code example, see How to: Add Web Browser Capabilities to a Windows Forms Application.

// Navigates to the URL in the address text box when 
// the ENTER key is pressed while the text box has focus.
void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
   if ( e->KeyCode == System::Windows::Forms::Keys::Enter &&  !this->TextBoxAddress->Text->Equals( "" ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
   }
}

// Navigates to the URL in the address text box when 
// the Go button is clicked.
void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if (  !this->TextBoxAddress->Text->Equals( "" ) )
   {
      this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
   }
}

// Updates the URL in TextBoxAddress upon navigation.
void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ )
{
   this->TextBoxAddress->Text = this->WebBrowser1->Url->ToString();
}
// Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}

// Navigates to the URL in the address box when 
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
    Navigate(toolStripTextBox1.Text);
}

// 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
    {
        webBrowser1.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}

// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender,
    WebBrowserNavigatedEventArgs e)
{
    toolStripTextBox1.Text = webBrowser1.Url.ToString();
}

' Navigates to the URL in the address box when 
' the ENTER key is pressed while the ToolStripTextBox has focus.
Private Sub toolStripTextBox1_KeyDown( _
    ByVal sender As Object, ByVal e As KeyEventArgs) _
    Handles toolStripTextBox1.KeyDown

    If (e.KeyCode = Keys.Enter) Then
        Navigate(toolStripTextBox1.Text)
    End If

End Sub

' Navigates to the URL in the address box when 
' the Go button is clicked.
Private Sub goButton_Click( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles goButton.Click

    Navigate(toolStripTextBox1.Text)

End Sub

' Navigates to the given URL if it is valid.
Private Sub Navigate(ByVal address As String)

    If String.IsNullOrEmpty(address) Then Return
    If address.Equals("about:blank") Then Return
    If Not address.StartsWith("http://") And _
        Not address.StartsWith("https://") Then
        address = "http://" & address
    End If

    Try
        webBrowser1.Navigate(New Uri(address))
    Catch ex As System.UriFormatException
        Return
    End Try

End Sub

' Updates the URL in TextBoxAddress upon navigation.
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
    ByVal e As WebBrowserNavigatedEventArgs) _
    Handles webBrowser1.Navigated

    toolStripTextBox1.Text = webBrowser1.Url.ToString()

End Sub

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control navigates to the specified URI and adds it to the end of the history list. Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

You can use the Navigate method to implement an address bar similar to the one in Internet Explorer.

See also

Applies to

Navigate(String)

Source:
WebBrowser.cs
Source:
WebBrowser.cs
Source:
WebBrowser.cs

Loads the document at the specified Uniform Resource Locator (URL) into the WebBrowser control, replacing the previous document.

public:
 void Navigate(System::String ^ urlString);
public void Navigate (string urlString);
member this.Navigate : string -> unit
Public Sub Navigate (urlString As String)

Parameters

urlString
String

The URL of the document to load.

Exceptions

This WebBrowser instance is no longer valid.

A reference to an implementation of the IWebBrowser2 interface could not be retrieved from the underlying ActiveX WebBrowser control.

Remarks

The WebBrowser control maintains a history list of all the Web pages visited during a browsing session. When you call this overload, the WebBrowser control navigates to the specified URI and adds it to the end of the history list. Use the GoBack method to return the control to a previous page in the navigation history. Use the GoForward method to return to a later page in the navigation history after navigating backward.

The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again. Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.

You can use the Navigate method to implement an address bar similar to the one in Internet Explorer.

See also

Applies to