IPhone development-real-time access to html content in UIWebView

Source: Internet
Author: User

On the Internet, I found a method to obtain the html content of a webpage by running a javascript script:

Get all html:


[Cpp] NSString * lJs = @ "document.doc umentElement. innerHTML ";
NSString * lJs = @ "document.doc umentElement. innerHTML ";

Obtain the webpage title:


[Cpp] NSString * lJs2 = @ "document. title ";
NSString * lJs2 = @ "document. title ";

The usage in WebView is as follows:


[Cpp] UIWebView * lWebView = [self getCurrentWebView];
NSString * lHtml1 = [lWebView stringByEvaluatingJavaScriptFromString: lJs];
NSString * lHtml2 = [lWebView stringByEvaluatingJavaScriptFromString: lJs2];
UIWebView * lWebView = [self getCurrentWebView];
NSString * lHtml1 = [lWebView stringByEvaluatingJavaScriptFromString: lJs];
NSString * lHtml2 = [lWebView stringByEvaluatingJavaScriptFromString: lJs2];


If you want to learn more about the content in webview, see:

Http://www.bkjia.com/kf/201202/120198.html

However, the above solution does not fully meet my requirements. I think it is to obtain html content in WebVIew in real time. The preceding method can only obtain html content during WebView initialization.

So he found the great stackoverflow. The solution is as follows:

Use the UIWebViewDelegate Protocol and implement the following methods in your delegate:


[Cpp] <span style = "font-size: 18px;">-(void) webViewDidFinishLoad :( UIWebView *) webView </span>
<Span style = "font-size: 18px;">-(void) webViewDidFinishLoad :( UIWebView *) webView </span>

Note: To set: www.2cto.com


[Cpp] <span style = "font-size: 18px;"> webView. delegate = self; </span>
<Span style = "font-size: 18px;"> webView. delegate = self; </span>

Reference: http://stackoverflow.com/questions/1662565/uiwebview-finished-loading-event


From the column zcl316369

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.