Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser control NavigateToString display HTML code instead of rendering page

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); 
like image 494
PutraKg Avatar asked Jan 23 '26 01:01

PutraKg


2 Answers

This is an issue with Windows Phone 8.

Here you have a workaround.

like image 153
vonLochow Avatar answered Jan 25 '26 16:01

vonLochow


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);
like image 28
keyboardP Avatar answered Jan 25 '26 15:01

keyboardP