如何返回到 WKWebView 历史记录中的起点 [英] How to goBack to startpoint in a WKWebView History

查看:36
本文介绍了如何返回到 WKWebView 历史记录中的起点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来向后跳转到 WKWebView 历史记录中的起点.

I'm trying to find a way to jump backwards to the startpoint in a WKWebView History.

假设我有一个带有 google.com 链接的主/起始页(WKWebView init).

Let's say i have a Main/Start-Page (WKWebView init) with a Link to google.com.

所以我点击链接,然后在 google.com 上点击另一个链接 ma​​ps.google.com.所以我离我的起始页只有 2 步之遥.

So i'm clicking at the Link and next at google.com i click another link maps.google.com. So i'm 2 steps away from my start-page.

如何在不重新加载或重新初始化 WKWebView 的情况下直接跳回主页面/起始页面?

How can i jump back directly to the Main/Startpage without reload or reinit the WKWebView ?

我尝试了以下实现但没有成功:

I have tried the following implementation but with no success:

-(void)backNavigationToStart{
    if([vuMain canGoBack]){
        WKBackForwardList *list = [vuMain backForwardList];
        if(list && list.backList){
            WKBackForwardListItem *item = [list itemAtIndex:0];
            [vuMain goToBackForwardListItem:item];
        }
    }
}

推荐答案

注意 -itemAtIndex 的 index 参数的含义:

Note the meaning of the index argument to -itemAtIndex:

所需列表项相对于当前项的索引:0 表示当前项,-1 表示前一项,1 表示后一项,依此类推."https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKBackForwardList_Ref/index.html#//apple_ref/occ/instm/WKBackForwardList/itemAtIndex:

"Index of the desired list item relative to the current item: 0 for the current item, -1 for the immediately preceding item, 1 for the immediately following item, and so on." https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKBackForwardList_Ref/index.html#//apple_ref/occ/instm/WKBackForwardList/itemAtIndex:

使用适当的负索引,或使用 backList 中的第一项.

Use an appropriate negative index, or use the first item in backList.

这篇关于如何返回到 WKWebView 历史记录中的起点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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