【问题标题】:Showing temporary data in a WebView在 WebView 中显示临时数据
【发布时间】:2024-01-20 14:16:01
【问题描述】:

我正在尝试制作一个基本上采用 .zip 文件(使用 FileOpenPicker)、提取 .zip 文件(在 Windows.Storage.ApplicationData.Current.TemporaryFolder 的子文件夹中)并尝试读取其中一个 HTML 页面的应用程序被提取出来了。

显然,WebView 无法从 ApplicationData 加载任何网页: http://msdn.microsoft.com/en-us/library/windows/apps/hh781215.aspx

Note that, for security reasons, you cannot navigate to HTML you have downloaded to this location and you cannot run any executable or potentially executable code, such as script or CSS. It is intended for media such as images or videos and the like.

WebView 中有一个名为NavigateToString 的方法,因此我可以将 .html 文件加载到内存中并导航到它。唯一的问题是,如果网页引用图像、css 或 zip 中其他页面的链接,我就完蛋了。我不太明白为什么当你可以使用 NavigateToString 做任何你想做的事情时他们不允许这样做......无论如何......

有什么解决方法可以实现我想要的吗?

【问题讨论】:

  • 您是否尝试过将 html 放入字符串中,删除旧的 html 文件,然后创建一个具有相同内容的新文件?

标签: c# webview windows-8 microsoft-metro windows-runtime


【解决方案1】:

解决方法是将所有内容(javascript、css、图像作为 base64 编码字符串)插入 html 并将其传递给 NavigateToString。根据网页的不同,它可能是可以实现的,也可能是几乎不可能的。我自己在一个应用程序中这样做,因为这是我找到的唯一方法。

【讨论】: