Cloud Training (Online)




How to retreive the page title from WebBrowser Control in Windows Phone?

If you are using a WebBrowser Control in your Windows Phone and want to retreive the page title of the webpage , you can do that easily by using the InvokeScript method defined in the web browser control in Windows Phone.

How to retreive the page title from WebBrowser Control in Windows Phone?

Below is a C# codebehind that demonstrated how to retreive the page title from WebBrowser Control in Windows Phone.

using System;
using System.Windows;
using Microsoft.Phone.Controls;
namespace PhoneApp4
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            webBrowser1.Navigate(new Uri("http://www.developerpublish.com",UriKind.RelativeOrAbsolute));          
        }

        private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            String title = (string)webBrowser1.InvokeScript("eval", "document.title");
            MessageBox.Show(title);
        }
    }
}

Below is a C# code converted to VB.NET code to demonstrate how to retreive the page title from WebBrowser Control in Windows Phone

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()
        WebBrowser1.Navigate(New Uri("http://www.developerpublish.com", UriKind.RelativeOrAbsolute))
    End Sub

    Private Sub WebBrowser1_Navigated(sender As System.Object, e As System.Windows.Navigation.NavigationEventArgs) Handles WebBrowser1.Navigated
        Dim title As [String] = DirectCast(WebBrowser1.InvokeScript("eval", "document.title"), String)
        MessageBox.Show(title)
    End Sub
End Class
How to retreive the page title from WebBrowser Control in Windows Phone?
How to retreive the page title from WebBrowser Control in Windows Phone?
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.