Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the height of a web view in iOS 10 [closed]

I need to get UIWebView height. in method webViewDidFinishLoad I have

CGFloat height1 = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] floatValue];
CGFloat height2 = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"] floatValue];
CGFloat height3 = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.clientHeight"] floatValue];
CGFloat height4 = [[webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.clientHeight"] floatValue];
CGFloat height5 = [[webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.scrollHeight"] floatValue];
CGFloat height6 = [[webView stringByEvaluatingJavaScriptFromString: @"document.documentElement.offsetHeight"] floatValue];

height = MAX(height1, MAX(height2, MAX(height3, MAX(height4, MAX(height5, height6)))));

and still all values are smaller then real value I have this problem only in iOS 10

like image 912
Sergey Burd Avatar asked Dec 31 '25 21:12

Sergey Burd


1 Answers

From Apple forums, your problem seem to have a solution

You can use the javascript func scrollHeight to find what you need.

NSString *heightStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];

You just need to convert it in a usable float value :

CGFloat webViewHeight = [heightStr floatValue];
like image 100
Victor Carmouze Avatar answered Jan 02 '26 11:01

Victor Carmouze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!