swift将网页保存在wkwebview中
我希望能够将任何网站保存在WKWebView中,并随时通过另一个按钮恢复它。
我尝试下载网站的HTML:
public func getHtml(completion: @escaping (String?, URL?) -> Void) {
webView.evaluateJavaScript("document.documentElement.outerHTML.toString()") { html, error in
let html = html as? String
completion(html, self.webView.url)
}
}
并使用以下方式恢复HTML webView.loadhtmlstring(html,baseurl:url)
,
但加载HTML会导致UI的格式失去格式:
I want to be able to save any website in a WKWebView, and restore it at anytime through another button.
I tried downloading the HTML of the website:
public func getHtml(completion: @escaping (String?, URL?) -> Void) {
webView.evaluateJavaScript("document.documentElement.outerHTML.toString()") { html, error in
let html = html as? String
completion(html, self.webView.url)
}
}
and restoring the html using:webView.loadHTMLString(html, baseURL: url)
But loading the html results in losing the formatting for the UI:
https://i.sstatic.net/Y3S7W.png
Is there a way to save / restore the formatting of the url?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论