CBFT
CBFT

Reputation: 302

Determine if WebBrowser Successfully loaded a page

Is there an easy way to find out if a WPF WebBrowser successfully loaded a page? I was able to figure out a workaround for HTML documents. It requires that I add the MSHTML reference to my DLL. I've been testing the code by trying to load "http://www.google.m". I used a non-existant website on purpose.

        Browser.LoadCompleted += HandleLoaded;
        private void HandleLoaded(object sender, NavigationEventArgs e)
        {
           if (_browser.Document is mshtml.HTMLDocument doc)
            {
                if (doc.title == "Navigation Canceled")
                { HandleInvalidAddress(); }
            }

        }

Upvotes: 0

Views: 136

Answers (1)

MattyMatt
MattyMatt

Reputation: 640

You want to read the ReadyState. It returns a WebBrowserReadyState value. You're looking for "Complete".

Upvotes: 0

Related Questions