Click here to Skip to main content
Click here to Skip to main content
Go to top

Windows Phone WebBrowser control: Manipulating Page DOM

, 18 Mar 2014
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.

Introduction

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.

Background

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.

Remarks

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:

License

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

Share

About the Author

Herbert Lausmann
Student
Brazil Brazil
No Biography provided

Comments and Discussions

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