************
#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