Click here to Skip to main content
12,826,621 members (24,047 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 18 Mar 2014

Windows Phone WebBrowser control: Manipulating Page DOM

, 18 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Shows how to manipulate the DOM of a page loaded in WebBrowser control of Windows Phone.


If you've programmed for Desktop (Windows Forms), you should know that WebBrowser control has a property called Document (of type HtmlDocument). This property allows us to manipulate the DOM of the page.

However, that property does not exist in the Windows Phone WebBrowser control. But there is still a way to manipulate the DOM of the page, which is using JavaScript.


Basically, my code uses the WebBrowser InvokeScript function to manipulate the DOM of the page with the help of JavaScript.

The code is based on the concept described in another of my articles:

An Important Thing

Before you start invoking scripts, first set the IsScriptEnabled property to True, otherwise it will not work.

Using the Code

Below is an example of DOM manipulation through JavaScript:

string script = "function() { return document.getElementById('ElementID').innerText; }";
string elementInnerText = (string)WebBrowser1.InvokeScript("eval", script);

In the above example, I use a small script to get the InnerText property of an element in the web page.


Unfortunately, I do not have the Windows Phone SDK installed. So I was unable to test the above code.

However, according to the theory and documentation, this is the right way.

If you get any exceptions when calling the method InvokeScript, try modifying your script. Remember that the same thing can be done in many ways.

I should point out that the same script may not work on all versions of Windows Phone, so you should test!

Original Source

This was originally posted on my personal blog (Brazilian Portuguese).
If you speak Portuguese, feel the urge to visit the original post:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Herbert Lausmann
Brazil Brazil
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 18 Mar 2014
Article Copyright 2014 by Herbert Lausmann
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid