How can I get the page title in WebBrowser control?

后端 未结 6 647
挽巷
挽巷 2021-02-13 20:00

How can I get the page title in a WebBrowser control when I navigate to different websites?


xmlns

xmlns:phone=\"clr-namespace:Microsoft.Phone.Contr         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-13 21:01

    The code below works for me, note the navigated event, if you use loaded it will trigger just before the page is loaded, you want that to trigger sometime "after" the page is Fully Loaded, navigated acts as that event.

    private void web1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            //Added thread using "using System.Thread", to act as a buffer for any page delay.
            Thread.Sleep(2000);
            String title = (string)web1.InvokeScript("eval", "document.title");
            PageTitle.Text = title;
    
        }
    

提交回复
热议问题