WKWebView 从 WKBackForwardList 中删除一项 [英] WKWebView remove one item from WKBackForwardList

查看:38
本文介绍了WKWebView 从 WKBackForwardList 中删除一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个小型浏览器,因此我希望能够在我的网络视图中前后导航.出于这些目的,我使用 WKWebView,但有时我需要显示一个 Error html 页面,并且我不希望将此页面存储在我的 WKBackForwardList 中.

I'm implementing a tiny browser, so I would like to be able to navigate back and forward on my web view. For these purposes I use WKWebView, but I need to display an Error html page sometimes, and I don't want this page to be stored in my WKBackForwardList.

有没有办法从 WKBackForwardList 中删除一项?我想这是一个非常普遍的问题,所以,我是否必须实现自己的历史功能?

Is there any way to remove one item from WKBackForwardList ? I guess that it is a really general issue, so, do I have to implement my own History functional?

推荐答案

现在很清楚 WKBackForwardList 是不可变的(例如,不能被修改).但是你可以通过搞乱本地网络服务器来实现这个结果.您创建一个错误页面,由本地网络服务器提供服务,并在出现错误时将其加载到网络视图中.但是本地网络服务器的行为是它加载一次错误页面,所有其他请求(从后退和前进)将导致重定向到导致错误的页面.BackFrowardList 不会按顺序存储重复的 url 地址,因此此页面 URL 只会出现一次.看看 Firefox iOS 版本实现 因为他们使用完全相同的技术.

It is clear for now that WKBackForwardList is immutable (e.g. cannot be modified). But you can achieve this result by messing up with local webserver. You create an error page, served by local webserver and load it in a webview in case of error. But the behaviour of the local webserver is so that it loads the error page once and all the other requests (from going back and forward) will lead to a redirect to the page which caused the error. BackFrowardList do not store duplicates of the url addresses in a sequence so this page URL will appear only once. Take a look at Firefox iOS version implementation because they use the exact same technique.

在历史部分,如果您只想在一个会话期间保留历史记录,您可以真正使用 BackForwardList 项.但是,如果您想在会话之间保留历史记录(WKWebView 销毁),则必须创建自己的历史记录存储.

On the history part, if you only want the history to persist during one session you can really make use of BackForwardList items. But if you want to persist the history between sessions (WKWebView destruction) you'll have to make your own history storage.

这篇关于WKWebView 从 WKBackForwardList 中删除一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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