WKWebView返回某个历史页面

/** 
 *  在发送请求之前,决定是否跳转 
 * 
 *  @param webView          实现该代理的webview 
 *  @param navigationAction 当前navigation 
 *  @param decisionHandler  是否调转block 
 */  
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {  
      
    if (navigationAction.navigationType==WKNavigationTypeBackForward) {                  //判断是返回类型  
        if (webView.backForwardList.backList.count>0) {                                  //得到栈里面的list  
            WKBackForwardListItem * item = webView.backForwardList.currentItem;          //得到现在加载的list  
            for (WKBackForwardListItem * backItem inwebView.backForwardList.backList) { //循环遍历,得到你想退出到  
                 //添加判断条件  
                [webView goToBackForwardListItem:[webView.backForwardList.backListfirstObject]];  
            }  
        }  
    }  
  
    //允许跳转  
    decisionHandler(WKNavigationActionPolicyAllow);  
}  

你可能感兴趣的:(WKWebView返回某个历史页面)