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/






document.width returns always width of iphone screen (320), document.height works fine.

– Alexander Ermolaev
Feb 14 '13 at 8:30







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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)