iOS 开发 WKWebView加载网页,对网页控件进行更改,使用OC添加JS

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljc_563812704/article/details/84317289

//获取加载的网页

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{

    NSLog(@"在收到响应后:%@",navigationResponse.response.URL.absoluteString);

    //允许跳转

    decisionHandler(WKNavigationResponsePolicyAllow);

    //不允许跳转

    //decisionHandler(WKNavigationResponsePolicyCancel);

}

//#pagram mark - WKNavigationDelegate

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {        

/       //像JS注入的字符串

        NSMutableString *JSStringM = [NSMutableString string];

        [JSStringM appendString:@"document.getElementById('new-menu-btn').style.visibility = 'hidden';"];

        //用evaluateJavaScript 注入代码即可。

       [webView evaluateJavaScript:JSStringM completionHandler:nil];

//    // 获取加载网页的标题

    self.title = self.webView.title;

}

猜你喜欢

转载自blog.csdn.net/ljc_563812704/article/details/84317289