I am developing a browser app using Windows Phone 8 browser control.
The app download an external webpage using WebClient into a string in the background. Then the browser navigate to the content using
webBrowser.NavigateToString(str);
However, instead of rendering the page, the browser shows the HTML code. I thought since no changes were made to the string, NavigateToString should handle it seamlessly. Or perhaps I am missing something.
So how do I display the HTML page instead of its code?
EDIT
Here's some of my code
webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(uri));
private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
PageString = e.Result;
}
...
webBrowser.NavigateToString(PageString);
This is an issue with Windows Phone 8.
Here you have a workaround.
When you use DownloadStringAsync, it also downloads the DOCTYPE declaration. You can remove this and start your code with the <html> block as NavigateToString doesn't seem to like the <!DOCTYPE HTML> declaration.
webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
webClient.DownloadStringAsync(new Uri(uri));
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//remove "<!DOCTYPE HTML>"
PageString = e.Result.Replace("<!DOCTYPE HTML>","").Trim();
}
webBrowser.NavigateToString(PageString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With