Skip to content

Instantly share code, notes, and snippets.

@kikohz
Created September 4, 2017 02:33
Show Gist options
  • Save kikohz/23fecb6145f7188551dae1a8148b9de3 to your computer and use it in GitHub Desktop.
Save kikohz/23fecb6145f7188551dae1a8148b9de3 to your computer and use it in GitHub Desktop.
/**
* 在发送请求之前,决定是否跳转
*
* @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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment