gpt4 book ai didi

objective-c - stringByEvaluatingJavaScriptFromString 识别webview内容高度

转载 作者:行者123 更新时间:2023-12-03 17:58:00 28 4
gpt4 key购买 nike

我将 Uiwebview 放置在 UIscrollview 中,因为在 uiwebview 之后我想使用 PageController 显示一些图像。

我正在使用这行代码。

   -(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)];


}

但是Web View 为%f高不起作用,它无法识别WebView的高度有人知道我该如何解决这个问题吗?这是因为我正在使用 [WebView loadHTMLString:html baseURL:nil];

并且: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];

最佳答案

尝试

NSString *heightString = [Bericht stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"];

祝你好运,内森

关于objective-c - stringByEvaluatingJavaScriptFromString 识别webview内容高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10553504/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com