Javascript 如何获取webview的当前内容大小?

Javascript 如何获取webview的当前内容大小?,javascript,ios,objective-c,uiwebview,margin,Javascript,Ios,Objective C,Uiwebview,Margin,当我在uiwebview中显示epub时,我可以看到480px以下有行,因此如何将内容大小高度限制为450px并添加50px的底部边距。目前我正在使用以下代码添加总填充,我不知道如何限制uiwebview的内容高度? NSString *padding = @"document.body.style.padding='15px 15px 15px 15px';"; [webView stringByEvaluatingJavaScriptFromString:padding]; 请帮帮我 我尝

当我在uiwebview中显示epub时,我可以看到480px以下有行,因此如何将内容大小高度限制为450px并添加50px的底部边距。目前我正在使用以下代码添加总填充,我不知道如何限制uiwebview的内容高度?

NSString *padding = @"document.body.style.padding='15px 15px 15px 15px';";
[webView stringByEvaluatingJavaScriptFromString:padding];
请帮帮我

我尝试使用此代码获取内容大小,但返回的值为14783

webView.scrollView.ContentSize.height然后我得到14783

试着在…上使用这个

CGSize contentSize = CGSizeMake([[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"] floatValue],
                                [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]);
编辑

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    CGRect frame = webView.frame;

    frame.size.height = 5.0f;

    webView.frame = frame;
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize mWebViewTextSize = [webView sizeThatFits:CGSizeMake(1.0f, 1.0f)];  // Pass about any size

    CGRect mWebViewFrame = webView.frame;


    mWebViewFrame.size.height = mWebViewTextSize.height;

    webView.frame = mWebViewFrame;


    //Disable bouncing in webview
    for (id subview in webView.subviews)
    {
        if ([[subview class] isSubclassOfClass: [UIScrollView class]])
        {
            [subview setBounces:NO];
        }
    }
}
请尝试以下代码:

- (void)webViewDidFinishLoad:(UIWebView *)webView1
{
      NSString  *totalHeight;

        totalHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"foo\").offsetHeight;"];

         if([totalHeight intValue] >= 450)
         {
            [webView setFrame:CGRectMake(0, 0, webView.frame.size.width, 450)];
         }
         else
         {
          [webView setFrame:CGRectMake(0, 0, webView.frame.size.width, [totalHeight floatValue])];
         }
}

我希望它能帮助您。

我可以用float打印这个吗?是的,您可以喜欢这个。NSLog(@“宽度=%f,高度=%f”,contentSize.width,contentSize.height);我得到了这个值2997593932020441088.000000作为内容大小的宽度或高度告诉我?你知道它的内容大小。它不是卷轴的高度。