how does one check if UIWebView is empty or not

前端 未结 4 735
醉话见心
醉话见心 2021-02-15 17:02

I need to check if a webview when completed loading has any content or not.

What I require is simple. Its a small webview strip at the bottom of my pages (like an advert

4条回答
  •  野性不改
    2021-02-15 17:50

    This is based on Jano's approach but should perform better:

    NSString *script = @"document.getElementsByTagName('body')[0].innerHTML.length";
    NSString *length = [self.webView stringByEvaluatingJavaScriptFromString:script];
    
    if (length.integerValue > 0) {
        NSLog(@"not empty");
    }
    

提交回复
热议问题