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?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...