Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

wkwebview 和 JS 自用

 1 -(void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation{
 2     //获取 当前页URL
 3     NSString *js = @"document.location.href";
 4     [self.webView evaluateJavaScript:js completionHandler:^(id _Nullable response, NSError * _Nullable error) {
 5         NSLog(@"response: %@", response);
 6     }];
 7     
 8 }
 9 
10 //这个调用只能放在 finish 里,不然会报JS 异常
11 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
12     NSString *js = @"headHide()";
13     [self.webView evaluateJavaScript:js completionHandler:^(id _Nullable response, NSError * _Nullable error) {
14         NSLog(@"\n error: %@", error);
15     }];
16 
17 }

 

posted on 2016-08-12 11:49  Sinner_Yun  阅读(207)  评论(0编辑  收藏  举报

导航