博客> 使用wkwebview交互
使用wkwebview交互
2020-02-24 13:05 评论:0 阅读:47 912612039
WKWebView

一、移除头部的导航栏 NSMutableString *str = [NSMutableString string]; // 3.根据标签类型获取指定标签的元素 [str appendString:@"var header = document.getElementsByTagName(\"header\")[0];"]; [str appendString:@"header[removed].removeChild(header)[0];"];//移除头部的导航栏 [str appendString:@"document.getElementsByClassName(\"container\")[0].style.paddingTop='0'"];//移除头部的导航栏 [self.webView evaluate[removed]str completionHandler:nil];

二、页面发送请求前,决定要不要跳转 //页面发送请求前,决定要不要跳转

  • (void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    if ([self.title isEqualToString:@"xxxxx"] && [webView.URL.absoluteString rangeOfString:@"xxxx.html"].location != NSNotFound && _isInto_ePay) { decisionHandler(WKNavigationActionPolicyCancel); _isInto_ePay = NO; [self popToView]; } else { //对第三方拨打电话的处理 NSLog(@"%@",navigationAction.request.URL.absoluteString); if ([navigationAction.request.URL.absoluteString rangeOfString:@"tel:"].location != NSNotFound) { [[UIApplication sharedApplication] openURL:navigationAction.request.URL]; decisionHandler(WKNavigationActionPolicyCancel); } else { //如果是跳转一个新页面 if(navigationAction.targetFrame ==nil) { [webView loadRequest:navigationAction.request]; } decisionHandler(WKNavigationActionPolicyAllow); } }

三、解决部分页面不跳转的问题

pragma mark 解决部分页面不跳转的问题

  • (WKWebView )webView:(WKWebView )webView createWebViewWithConfiguration:(WKWebViewConfiguration )configuration forNavigationAction:(WKNavigationAction )navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures{ NSLog(@"createWebViewWithConfiguration"); if (!navigationAction.targetFrame.isMainFrame) { [webView loadRequest:navigationAction.request]; } return nil; }
收藏
0
sina weixin mail 回到顶部