Get the height of the WebView iOS

created at 09-12-2021 views: 13
-(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];
       //If there is a problem with the scrollHeight method, you can find the webview to discuss and get the lastLinediv to try
//        NSString *meta = @"document.getElementById(\"lastLinediv\").offsetTop";
        NSString *meta = @"document.body.scrollHeight";
        [webView evaluateJavaScript:meta completionHandler:^(id _Nullable result,NSError * _Nullable error){
            //height of webview
            CGFloat newHeight = [result floatValue]*ratio;

        }];
    }];
}
created at:09-12-2021
edited at: 09-12-2021: