iOS web Seventh day Webview-02webview and Web page interaction 2, delete the public comments extra text, plus mask progress

Source: Internet
Author: User

************

#import "HMViewController.h"@interfaceHmviewcontroller () <UIWebViewDelegate>@property (nonatomic, weak) Uiactivityindicatorview*Loadingview;@end@implementationHmviewcontroller/** test.html exists in the server, the inside of the HTML and JS code, we can not modify if test.html display on the phone side, the UL removed*/- (void) viewdidload{[Super Viewdidload]; //1.webViewUIWebView *webview =[[UIWebView alloc] init]; Webview.frame=Self.view.bounds; WebView.Delegate=Self ; //stretch the page to fill the entire WebViewWebview.scalespagetofit =YES; //Hide ScrollViewWebView.scrollView.hidden =YES;        [Self.view Addsubview:webview]; //2. Loading Web pagesNsurlrequest *request = [Nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://m.dianping.com/tuan/deal/5501525"]];        [WebView Loadrequest:request]; //3. Create a circleUiactivityindicatorview *loadingview =[[Uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhitelarge];    [Loadingview startanimating]; Loadingview.center= Cgpointmake ( the, -);    [Self.view Addsubview:loadingview]; Self.loadingview=Loadingview;}//OC-JS//invoking JS in OC#pragmamark-uiwebviewdelegate-(void) Webviewdidfinishload: (UIWebView *) webview{//Execute the JS code and delete the redundant nodes in the public comments page//var html = Document.body.innerHTML;//nsstring *html = [WebView stringbyevaluatingjavascriptfromstring:@ "Document.body.innerHTML;"];//NSLog (@ "%@", html);nsmutablestring*JS1 = [nsmutablestringstring]; //0. Remove the top navigation bar[Js1 appendString:@"var header = document.getElementsByTagName (' header ') [0];"]; [Js1 appendString:@"Header.parentNode.removeChild (header);"]; //1. Delete the link at the bottom[Js1 appendString:@"var footer = document.getelementsbytagname (' footer ') [0];"]; [Js1 appendString:@"footer.parentNode.removeChild (footer);"];        [WebView STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:JS1]; Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.25* nsec_per_sec)), Dispatch_get_main_queue (), ^{nsmutablestring*JS2 = [nsmutablestringstring]; //2. Delete a floating ad[Js2 appendString:@"var list = document.body.childNodes;"]; [Js2 appendString:@"var len = list.length;"]; [Js2 appendString:@"var banner = list[len-1];"]; [Js2 appendString:@"banner.parentNode.removeChild (banner);"];                [WebView STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:JS2]; //Show ScrollViewWebView.scrollView.hidden =NO; //Delete Circle[Self.loadingview Removefromsuperview]; });}@end

iOS web Seventh day Webview-02webview and Web page interaction 2, delete the public comments extra text, plus mask progress

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.