- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSLog(@"开始请求: %@ \n\n", navigationAction.request);
NSLog(@"navigationAction: %@ \n\n", navigationAction);
[self showBigImage:navigationAction.request];
NSString *urlString = [navigationAction.request.URL absoluteString];
if ([urlString containsString:@"m-web/info/infodetail/"]) {
HPNewsDetailNewVC *newsD = [[HPNewsDetailNewVC alloc] initWithNewsID:[urlString componentsSeparatedByString:@"/"].lastObject];
[self.navigationController pushViewController:newsD animated:YES];
// 不允许web内跳转
decisionHandler(WKNavigationActionPolicyCancel);
}else if ([urlString containsString:@"m-web/activity/detail/"]) {
HPAcitivityNewDetailVC *nv = [[HPAcitivityNewDetailVC alloc] initWithID:[urlString componentsSeparatedByString:@"/"].lastObject];
[self.navigationController pushViewController:nv animated:YES];
// 不允许web内跳转
decisionHandler(WKNavigationActionPolicyCancel);
}else if ([urlString containsString:@"m-web/train/all/"]) {
HPTrainDetailVC2 *vc = [[HPTrainDetailVC2 alloc] initWithCourseId:[urlString componentsSeparatedByString:@"/"].lastObject courseGuid:nil courseApplyId:nil];
[self.navigationController pushViewController:vc animated:YES];
// 不允许web内跳转
decisionHandler(WKNavigationActionPolicyCancel);
}else {
decisionHandler (WKNavigationActionPolicyAllow);
}
// if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {//跳转别的应用如系统浏览器
// // 对于跨域,需要手动跳转
//// [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
//
// // 2.跳转别的应用如系统浏览器(跨域跳转)、应用的web内跳转(不跨域跳转)
// // NSString *hostname = navigationAction.request.URL.host.lowercaseString;
//
// } else {//应用的web内跳转
// decisionHandler (WKNavigationActionPolicyAllow);
// }
}
网友评论