0

我的视图控制器中有一个 uiwebview,用于显示 epub 内容,如何从 UIWebView 获取 NSString 中的内容?这段代码对我不起作用

NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerHTML"]; 
4

2 回答 2

1

试试这个:

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];//may be `"document.body.innerText;"`
于 2013-03-26T05:49:22.097 回答
0

使用此委托确保在显示内容之前加载 Web 视图:

  - (void)webViewDidFinishLoad:(UIWebView *)webView
   {
    if(!webView.isLoading){
       //if you need to get all ressources
        NSString html=[webView    stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
       //if you need just the content of Body
       NSString html=[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
         }

    }
于 2015-06-09T12:32:28.757 回答