Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding article for DotNetBrowser 2 here.
To load a web page by its URL use the Browser.LoadURL()
method.
The following code demonstrates how to load http://www.google.com web page:
C#
browser.LoadURL("http://www.google.com");
VB.NET
browser.LoadURL("http://www.google.com")
Same method can be used for loading a HTML file from a local file system. Instead of URL you just need to provide absolute path to HTML file. For example:
C#
browser.LoadURL("C:\\path\\index.html");
VB.NET
browser.LoadURL("C:\path\index.html")
The web page will be loaded asynchronously (it doesn't block current thread execution), so there's no guarantee that Google web page will be loaded completely when the method returns.
The Browser.Loading
property will return true if the Browser
instance is currently loading resources. To stop loading page and cancel any pending navigation or download operation use Browser.Stop()
. In addition, the call to this method stops any dynamic page elements, such as background sounds and animations.
You can use the FinishLoadingFrameEvent
to be informed when the main frame is loaded. At that point, you can assume that the page is loaded completely and execute JavaScript, work with DOM, etc. See Loading URL Synchronously
Since 1.8.1 it is possible to determine browser is currently loading something. The Browser.Loading
property will return true in this case.
Example
C#
using System; using DotNetBrowser; namespace MyNamespace { class Program { static void Main(string[] args) { // Create Browser instance. Browser browser = BrowserFactory.Create(); // Load "http://www.google.com" URL browser.LoadURL("http://www.google.com"); // Dispose Browser instance. browser.Dispose(); } } }
VB.NET
Imports DotNetBrowser Module Module1 Sub Main(args As String()) ' Create Browser instance. Dim browser As Browser = BrowserFactory.Create() ' Load "http://www.google.com" URL browser.LoadURL("http://www.google.com") ' Dispose Browser instance. browser.Dispose() End Sub End Module