UIWebView and Web page interaction (OC-in-Tune execution JS)
-(void) viewdidload
{
[Super Viewdidload];
1.webView
UIWebView *webview = [[UIWebView alloc] init];
Webview.frame = Self.view.bounds;
Webview.delegate = self;
Stretch the page to fill the entire WebView
Webview.scalespagetofit = YES;
Hide ScrollView
WebView.scrollView.hidden = YES;
[Self.view Addsubview:webview];
2. Loading Web pages
Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@ "http://m.dianping.com/tuan/deal/5501525 "]];
[WebView Loadrequest:request];
3. Create
Uiactivityindicatorview *loadingview = [[Uiactivityindicatorview alloc] Initwithactivityindicatorstyle: Uiactivityindicatorviewstylewhitelarge];
[Loadingview startanimating];
Loadingview.center = Cgpointmake (160, 240);
[Self.view Addsubview:loadingview];
Self.loadingview = Loadingview;
}
Invoking JS in OC
#pragma mark-uiwebviewdelegate
-(void) Webviewdidfinishload: (UIWebView *) WebView
{
nsmutablestring *js1 = [nsmutablestring string];
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 = [nsmutablestring string];
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 ScrollView
WebView.scrollView.hidden = NO;
Delete Circle
[Self.loadingview Removefromsuperview];
});
}
Note: Get data from the network, if you do not want to see an effect, and the Web page is stored on the server side, the inside of the JS and HTML code, there is no way to modify, you can execute the JS code in the UIWebView proxy method, remove the effect you do not want to see.
IOS UIWebView and Web page interaction (OC in tune to execute JS)