1

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 ...

Sarah T
  • 119
  • 2
  • 16
  • if submit is in same folder as index.html, then change your index.html to show as ms-appx-web://Submit.html and it should work. – AVK Feb 13 '17 at 15:18
  • Tried all combinations of file, URL etc. - all are visible in the navigation event but no page is shown. The two files work perfectly on all browsers tested - I just cant show a linked page in the Web view. All my other functions on the DOM work fine. – Sarah T Feb 13 '17 at 15:37

1 Answers1

1

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.

Community
  • 1
  • 1
Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • Yes you are correct a change to get fixed this issue, may I ask where you leaned this information as I did not spot this as an issue in the ms docs. – Sarah T Feb 16 '17 at 21:39
  • @SarahT, This is not the uwp relative knowledge actually. I'm sorry I also haven't seen this information on uwp relative documents. Just according to the HTML [form](http://html.com/attributes/form-method/) tag definition that post requires server side support and may be I had experiences on writing code deal with post requirements code behind in a MVC project. – Sunteen Wu Feb 17 '17 at 01:40
  • Many Thank - you have been a great help. – Sarah T Feb 24 '17 at 11:09