简体   繁体   English

Windows 10 UWP Webview 本地url问题

[英]Windows 10 UWP Webview local url problems

Windows 10 UWP Webview Windows 10 UWP 网页视图

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.我有两个 html 文件位于 Windows 10 UWP 中 Assets (Assets/www/xxx.html) 下的 www 文件夹中,VS 2015 中的两个文件都设置为复制到输出目录。

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 对象嵌入在 XMAL 中,如下所示

<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.页面加载并正确显示,但不会显示链接的“submit.html”页面,它只是空白。

If I trap the Navigation event it does occur but appears to be prefixed by a GUID as show below.如果我捕获导航事件,它确实会发生,但似乎以 GUID 为前缀,如下所示。

在此处输入图片说明 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 ...想法请伙计们...

If I trap the Navigation event it does occur but appears to be prefixed by a GUID as show below如果我捕获导航事件,它确实会发生,但似乎以 GUID 为前缀,如下所示

The "GUID" is the package name of current app, it is the default value of Authority part of URI schemes . “GUID”是当前应用程序的包名,它是URI 方案授权部分的默认值。 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");可以通过代码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页面加载并正确显示,但不会显示链接的“submit.html”页面,它只是空白

For your issue, I change the form method to get , it will work.对于您的问题,我将form方法更改为get ,它将起作用。

<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. form有两种提交表单数据的方法。 Get sends form data via a URL string, post sends form data via the server. Get 通过 URL 字符串发送表单数据,post 通过服务器发送表单数据。 In my opinion, post method post data firstly and then navigate, and the data are handled at server side.在我看来,post方法是先发布数据然后导航,数据在服务器端处理。 I haven't seen posted form data received and handled on a HTML page, so I guess you did not need use post method.我还没有看到在 HTML 页面上接收和处理发布的表单数据,所以我猜你不需要使用 post 方法。 For get method you can receive data and deal them in javascript, here is how to do.对于 get 方法,您可以接收数据并在 javascript 中处理它们, 是如何做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM