将本地 HTML 加载到 WebView [英] Load local HTML into WebView

查看:79
本文介绍了将本地 HTML 加载到 WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将本地 HTML 文件(包含图像和...)加载到 WebView 中吗?
仅设置 Source 参数并不能解决问题.

Can I load a local HTML file (with images and ...) into a WebView?
Just setting the Source parameter does not do the trick.

推荐答案

只要文件是应用程序包的一部分,您就可以从文件中加载它,例如:

You can load it from a file as long as the file is part of the app package, e.g.:

WebView2.Source = new Uri("ms-appx-web:///assets/text.html");

来自 WebView.导航

WebView 可以从应用程序包中加载内容,使用ms-appx-web://,来自使用 http/https 的网络,或来自字符串使用 NavigateToString.它无法从应用程序加载内容数据存储.访问内网,对应能力必须在应用清单中打开.

WebView can load content from the application’s package using ms-appx-web://, from the network using http/https, or from a string using NavigateToString. It cannot load content from the application’s data storage. To access the intranet, the corresponding capability must be turned on in the application manifest.

对于随机"文件,我想您可以通过文件选择器提示用户选择文件,然后将其读入字符串并使用 NavigateToString,但用户体验可能有点奇怪,具体取决于您要尝试的内容完成.

For a 'random' file, I suppose you could prompt user via file picker to select the file then read it into a string and use NavigateToString, but the user experience there may be a bit odd depending on what you're trying to accomplish.

这篇关于将本地 HTML 加载到 WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆