Sarah T
Sarah T

Reputation: 129

Windows 10 UWP Webview local url problems

Windows 10 UWP Webview

I have the two html files located in a www folder under Assets (Assets/www/xxx.html) in a Windows 10 UWP, both files in VS 2015 are set to be copied to the output dir.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Simple Script</title>
</head>

<body>
    <form action="submit.html" method="post">
    Data:<input type="text" name="somedata" > <br> <br>
    <input type="submit" value="Submit" >
    </form>
</body>
</html>

and submit.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Dummy Submission</title>
</head>

<body>
  <h2> Your data has been submitted - Thank You. </h2>
</body>
</html>

The Webview object is embbeded in the XMAL as below

<WebView  x:Name="WebBrowser" HorizontalAlignment="Left" VerticalAlignment="Top"  Height="532" Width="1014" NavigationStarting="WebBrowser_NavigationStarting"/>

And the index page is loaded by

    /// Helper to perform the navigation in webview
    /// </summary>
    /// <param name="url"></param>
    private void NavigateWebview(string url)
    {
        try
        {
            Uri targetUri = new Uri(url);
            WebBrowser.Navigate(targetUri);
        }
        catch (FormatException myE)
        {
            // Bad address
            WebBrowser.NavigateToString(String.Format("<h1>Address is invalid, try again.  Details --> {0}.</h1>", myE.Message));
        }
    }


NavigateWebview(@"ms-appx-web:///Assets/www/index.html");

The page loads and displays correctly but it will not display the linked 'submit.html' page, its just blank.

If I trap the Navigation event it does occur but appears to be prefixed by a GUID as show below.

enter image description here I have changed paths to absolute etc and read the docs in detail but I fail to see why this does not work.

Ideas Please Guys ...

Upvotes: 1

Views: 1377

Answers (1)

Sunteen Wu
Sunteen Wu

Reputation: 10627

If I trap the Navigation event it does occur but appears to be prefixed by a GUID as show below

The "GUID" is the package name of current app, it is the default value of Authority part of URI schemes. So if you only want to navigate to another page, this absolutely path is right. You can test by code NavigateWebview(@"ms-appx-web://{your package name}/Assets//www/submit.html");

The page loads and displays correctly but it will not display the linked 'submit.html' page, its just blank

For your issue, I change the form method to get, it will work.

<form action="submit.html"  method="get" id="myform">
    Data:<input type="text" name="somedata"> <br> <br>
    <input type="submit" value="Submit">
</form>
<a href="submit.html">Please Click Me to jump</a>

form has two methods for submiting the form data. Get sends form data via a URL string, post sends form data via the server. In my opinion, post method post data firstly and then navigate, and the data are handled at server side. I haven't seen posted form data received and handled on a HTML page, so I guess you did not need use post method. For get method you can receive data and deal them in javascript, here is how to do.

Upvotes: 1

Related Questions