获取WKWebView内容高度(H5原生)

wkwebView代理方法



- (void)webView:(WKWebView*)webView didFinishNavigation:(null_unspecifiedWKNavigation*)navigation{ [webView evaluateJavaScript:@"document.getElementById(\"testDiv\").offsetTop"completionHandler:^(id_Nullable result,NSError* _Nullable error) {//获取页面高度,并重置webview的frameCGFloatlastHeight = [result doubleValue]; webView.frame =CGRectMake(14,0, CurrentScreenWidth -28, lastHeight); webHeight = lastHeight; [self.tableView beginUpdates]; [self.tableView endUpdates]; }]; }


不管你的网页是什么样的,在尾部加一个div它的位置永远是你需要的高度.(一定要注意<meta content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=0;" name="viewport" />这段代码不加的话高度不准


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容