iOS 获取网页标题

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
   
    if(self.showTopBarTitle){
        [self getTitle];
}

// 获取标题
- (void) getTitle {
    
    NSString *titleJs = @"document.title";
    [self.webView evaluateJavaScript:titleJs completionHandler:^(id result, NSError *error) {
        if (error == nil) {
            if (result != nil) {
                NSString *resultString = [NSString stringWithFormat:@"%@", result];
                self.naviBar.titleLabel.text = resultString;
            }
        }
    }];
}

或者

-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
   
                self.naviBar.titleLabel.text = self.webView.title;

}

你可能感兴趣的:(ios,objective-c,android)