Wednesday, August 31, 2011

Windows Phone 7 - NavigateToString, WebBrowser, and anchors

I needed to show some html in a page, using a WebBrowser control and the NavigateToString method.

The html was ok; it has some anchor in it to move from a section to another.

When I tested it in a standard web browser, or loading it with the phone IE9, worked perfectly.

But when I loaded the same html in the app page, using as I said the Navigatetostring method, the anchors didn't work anymore.

Then I tried to use some javascript to move to the anchors, using location.replace(#anchorname) – but again when I tested the html outside the app it worked… but not in the app.

I posted the question to the MSDN Forums, end Eric Fleck suggested me to use another approach, while confirming that the wrong behavior is in the latest RC of the WP7 tools.

The new approach is described in detail in this MSDN page, and basically uses IsolatedStorage to save the html fragments in order to load them in the WebBrowser using the .Navigate method. This way all the anchor links work… and I’m happy Sorriso

G’day everybody!

No comments: