将 HTML 从 WebView 保存到文档目录中的现有文件

发布于 2024-12-29 04:25:34 字数 133 浏览 3 评论 0原文

我一直在编写一些加载和保存 HTML 文件的代码。我已经能够创建它们,但是在 WebView 中编辑它们后,我需要将 HTML 文件从 webView 保存回文档目录。但是我不确定如何创建 HTML 文件。我将不胜感激你的帮助。我有文档文件路径和标题。

I have been working on some code that loads and saves HTML files. I have been able to create them, but after they are edited in the WebView, I need to save an HTML file from the webView back to the documents directory. I am not sure how to create the HTML file however. I would appreciate your help. I have the document file path and title.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2025-01-05 04:25:34

我能想到的唯一方法是使用 javascript 提取 html。例如,如果您引用了名为 webView 的 UIWebView 对象,则以下内容将返回包含内部 html 的字符串:

[bodyView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]);

然后您可以将其重新装回完整的 html 页面,javascript 将仅返回 < 中的内容;body> 标签。大概在加载然后编辑 html 页面的代码中,您可以知道并因此存储 标记之外发生的任何特定信息,以便可以恢复它?

The only way I can think of doing this is with javascript to pull out the html. For example if you have a reference to your UIWebView object called webView the following would return a string containing the inner html:

[bodyView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]);

You could then dress it back up to a complete html page, the javascript will only return the content within the <body> tags. Presumably within your code that loads and then edits the html page you can know, and therefore store, any specific information that occurred outside of the <body> tags such that you can restore it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文