How to get content width of uiwebview?
How to get content width of uiwebview?
I load Gif image like this
[webView2 loadData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apple_jumps" ofType:@"gif"]] MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
and I want to set to center position of uiwebview, but I can't to get width of content. Please help.
1 Answer
1
You can use document.height
or document.width
from javascript
document.height
document.width
// in init
_WebView.delegate = YourClass; // probably self
- (void) webViewDidFinishLoad:(UIWebView *)webview
int w = [[_WebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
_WebView.userInteractionEnabled = w > 200;
more info here: https://www.albertopasca.it/whiletrue/objective-c-get-uiwebview-html-page-size/
No, document.width return the width of your page. If your page use meta tags for iphone, size is 320px.
– elp
Oct 17 '13 at 10:50
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
document.width returns always width of iphone screen (320), document.height works fine.
– Alexander Ermolaev
Feb 14 '13 at 8:30