也就是html中的history.go(-1)
html代码
<button class="btn btn_primary" onclick="goBack()">返回</button>
function goBack()
{
window.history.go(-1);
}
这时候网页监听便会走
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
if (navigationAction.navigationType == WKNavigationTypeBackForward) {
NSLog(@"goback");
}
decisionHandler(WKNavigationActionPolicyAllow);
}
打印出goback
网页的历史记录
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
if (navigationAction.navigationType==WKNavigationTypeBackForward) {
if (webView.backForwardList.backList.count>0) {
WKBackForwardListItem * item = webView.backForwardList.currentItem;
for (WKBackForwardListItem * backItem in webView.backForwardList.backList) {
[webView goToBackForwardListItem:[webView.backForwardList.backListfirstObject]];
}
}
}
decisionHandler(WKNavigationActionPolicyAllow);
}