External Javascript not working with C# and XAML windows phone app RRS feed

  • Question

  • I've added a WebView into my project. If I navigate to the html file that contains external javascript files they don't work. Bit if I write the javascript code hardcoded into the html file it works properly.

    Here is the html portion:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <meta charset="utf-8" />
        <script type="text/javascript" src="testjs.js"></script>
        <div id="abcd"></div>
        hello! this is a simple html block. 

    Here is the javascript portion:

    document.getElementById("abcd").innerHTML = "New text!";

    When I open the webview it shows

    hello! this is a simple html block.,

    but if the javascript code worked it would show

    New Test! hello! this is a simple html block.

    And in the C# code the uri is called this way:

    url = onlineTestWebView.BuildLocalStreamUri("myUrl", "problem_page/test.html");
                StreamUriWinRTResolver myResolver = new StreamUriWinRTResolver();
                onlineTestWebView.NavigateToLocalStreamUri(url, myResolver);

    • Edited by mostafiz93 Saturday, March 14, 2015 9:38 PM code snippet added
    Thursday, March 12, 2015 10:14 AM

All replies

  • I assume this is because you are using NavigateToString. Please see http://blogs.msdn.com/b/wsdevsol/archive/2014/06/20/a-primer-on-webview-navigatetolocalstreamuri.aspx

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, March 12, 2015 6:20 PM
  • I didn't use NavigateToString method. C# code snippet is added.
    Saturday, March 14, 2015 9:40 PM
  • Submit a sample to show more information, we can say nothing according to the available code snippet.
    Monday, March 16, 2015 6:06 AM