2012-02-22 81 views
0

我试图在章节中将epub文件加载到webview中。我想知道屏幕的宽度。如何从iPhone中的JavaScript获得滚动宽度

例如:

if the content have one and half page text means it returns the width to be as 768 
but 
if the content have two full page text means it returns the width to be as 1536 

我的代码是:

int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] intValue]; 

回答

0

使用此

[[web视图stringByEvaluatingJavaScriptFromString:@ “document.body.scrollWidth”]的intValue];

“document.body.scrollWidth”返回您的UIWebView内容大小。

+0

这也返回相同的方式,是否有任何纠正这个 – dineshprasanna 2012-02-22 11:11:17

+0

使用此内部 - (void)webViewDidFinishLoad:(UIWebView *)webView方法您将获得网页内容的正确滚动宽度。 – 2012-02-22 11:22:02

+0

- (void)webViewDidFinishLoad:(UIWebView *)webView int totalWidth = [[webView stringByEvaluatingJavaScriptFromString:@“document.documentElement.scrollWidth”] intValue]; 我还没有得到滚动宽度先生。 这里我只把里面先生 } – dineshprasanna 2012-02-22 11:56:31