-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { [webView evaluateJavaScript:@"document.body.scrollWidth"completionHandler:^(id _Nullable result,NSError * _Nullable error){ CGFloat ratio = CGRectGetWidth(webView.frame) /[result floatValue]; //如果scrollHeight方法有问题 可以找webview商议获得lastLinediv试试 // NSString *meta = @"document.getElementById(\"lastLinediv\").offsetTop"; NSString *meta = @"document.body.scrollHeight"; [webView evaluateJavaScript:meta completionHandler:^(id _Nullable result,NSError * _Nullable error){ //webview的高度 CGFloat newHeight = [result floatValue]*ratio; }]; }]; }
原文:https://www.cnblogs.com/huangzs/p/15237447.html