UIWebView,在页面内容加载完成的代理方法中执行:
public func webViewDidFinishLoad(_ webView: UIWebView){
NSInteger height = [[webView stringByEvaluatingJavaScriptFromString:
@"document.body.scrollHeight"] integerValue];
}
WKWebView:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.body.scrollHeight") { (value, error) in
if error == nil{
debugPrint("webView的高度为:\(String(describing: value))")
}
}
}
网友评论