Ian Lundberg Ian Lundberg - 7 months ago 78
C# Question

How to get the URL of a WebBrowser control

if (webBrowser1.Url.AbsoluteUri == "www.google.com")
label9.Text = webBrowser1.Url.AbsoluteUri;

This is my current code. When I press the button to run this I get the error.

Object reference not set to an instance of an object.

And I don't know why it does that or how to fix it. Any help will be great.

Also It have to work in a timer so that it can be checked.


probably your webBrowser1.Url is null try below to get url

    string url = "";
    if (webBrowser1.Url != null)
        url = webBrowser1.Url.AbsoluteUri;
    if (url == "www.google.com")
        label9.Text = url;