locked
NavigateToString and base uri info

    Question

  • I'm currently creating a app for WinRT (Windows 8.1/Windows Phone 8.1).

    Part of the app needs to show a piece of HTML (retrieved from a JSON based webservice). I currently do this like this:

    private async void LoadWebviewSource()
    {
        //Load content async
        //..
        string baseUrl = result.HtmlContentBaseUri; //Base Uri for url and javascript resolving in html content
        string htmlString = result.HtmlContent;
        MyWebView.NavigateToString(htmlString);
    }

    The issue here is that I'm unable to set the base uri for the loaded content. Because of this the url/javascript resolving in the webview fails. (Images won't load and JavaScript properties like document.location.protocol are set to about: , which some of the Javascript code in the loaded content doesn't like)

    In the Android and iOS webviews using the loadDataWithBaseURL methods on the webview works fine, the images load and all JavaScript properties are properly set.

    Is there a similar method available for the WinRT webview?

    I already tried setting the BaseUri property but it seems to be readonly. I also tried adding a <base> tag to the html head content after loading it and while this does resolve the image resolving issue, some JavaScript properties are still not set properly (Example: document.location.protocol is still about:)



    Sunday, December 21, 2014 10:44 AM

Answers

  • Hi Leon,

    >> Is there a similar method available for the WinRT webview?

    Yes, WebView provides NavigateToLocalStreamUri method to load HTML and support files (Such as CSS, Script and images). But per my understanding, you should save those file into local storage first. See a code sample about how to use this method. https://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7.

    Please feel free to let me know if I have any misunderstanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, December 22, 2014 9:15 AM
    Moderator