Reputation: 891
I am trying to get the height of the content in my UIWebView after I have loaded the content. I found this example somewhere...
NSInteger height = [[descriptionWebView stringByEvaluatingJavaScriptFromString:
@"document.documentElement.scrollHeight"] integerValue];
but this just gives me the height of the UIWebView container.
I am trying to get the height of the content so I can expand the UIWebView height to show all the content with no scrolling side the webview itself.
Upvotes: 0
Views: 484
Reputation: 59
You can use the script like this:
[[descriptionWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue];
Upvotes: 1
Reputation: 6530
I would go with a kind of hacky, but reliable way. First, I watch for shouldStartLoadWithRequest. That catches location.href= changes. Then I just define my own protocol, e.g
location.href='debug://width='+$(window).height();
Your ObjC code catches that, checks the link, parses it and cancels the navigation.
For your own content, you can just include it, otherwise you must inject the necessary javascript. I haven't tried that myself, but there appears to be lots of solutions for it:
Inject a local javascript into UIWebView
Upvotes: 0