how does one check if UIWebView is empty or not

前端 未结 4 754
醉话见心
醉话见心 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:56

    If you are loading a HTML page:

    NSString *string = [myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"];
    BOOL isEmpty = string==nil || [string length]==0;
    

    Or you could load the content first, test if it is not empty, and then feed it to the webview. See UIWebView's loadHTMLString:baseURL: or loadData:MIMEType:textEncodingName:baseURL:.

提交回复
热议问题