[英]stringByEvaluatingJavaScriptFromString recognize webview content height
i placed a Uiwebview in a UIscrollview because after the uiwebview i want to display some images with the PageController. 我在UIscrollview中放置了一个Uiwebview,因为在uiwebview之后,我想使用PageController显示一些图像。
i'm using this line of code. 我正在使用这一行代码。
-(void)webViewDidFinishLoad:(UIWebView *)webView{
if (webView!=WebView)return;
float h;
NSLog(@"web view is %f high", WebView.frame.size.height);
NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"body\").offsetHeight;"];
NSLog(@"web content is %@ high",heightString);
h = [heightString floatValue] +12.0f;
WebView.frame = CGRectMake(WebView.frame.origin.x, WebView.frame.origin.y, WebView.frame.size.width, h);
h = WebView.frame.origin.y + h + 20;
[ScrollView setContentSize:CGSizeMake(320, h)];
}
But Web view is %f high
doesn't work, it does not reconize the height of the WebView does anyone know how i can fix this? 但是,
Web view is %f high
无法正常工作,它无法协调WebView的高度,有人知道我可以解决此问题吗? Is this because i'm using [WebView loadHTMLString:html baseURL:nil];
这是因为我正在使用
[WebView loadHTMLString:html baseURL:nil];
And: NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\\"body\\").offsetHeight;"];
并且:
NSString *heightString = [WebView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\\"body\\").offsetHeight;"];
NSString *html = [NSString stringWithFormat:@"<html><head><!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><style>body { font: normal 13px helvetica; color: #565656; } </style></head><body><p>%@</p></body></html> ",text];
[WebView loadHTMLString:html baseURL:nil];
Try 尝试
NSString *heightString = [Bericht stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"];
Good luck, Nathan 内森,祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.