We have used this technique in the recent project development, so let's take a look.
- 1. Use the WebView control to load the local HTML5 or network HTML5
- 2. Set the controller as WebView agent, abide by the protocol
- 3. Implementing Proxy Methods
webViewDidFinishLoad:
- 4. In the agent method to operate the label in the HTML5 (crud--> additions and deletions)
- 1. Select the label to be manipulated using the class selector or the ID selector or tag Selector, etc.
- 2. Convert the selected label to a string
- 3.webView Calling
stringByEvaluatingJavaScriptFromString
method
- Application scenario: For example, load the network Baidu link, but do not want it a link tag, use this proxy method, get this tag, and then delete it, or change the display text of his tag and other content
1. Load Local HTML5
Nsurl *url = [[NSBundle mainbundle] Urlforresource:@ "test" withextension:@ " HTML"*request = [Nsurlrequest requestwithurl:url];[ Self.webview Loadrequest:request];
2. Load the Web page HTML5
Nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"*request = [ Nsurlrequest Requestwithurl:url]; [Self.webview loadrequest:request];
3. Delete a tag in HTML5, such as a button, in OC
// This method of invoking the proxy is called when the page view is loaded -(void) Webviewdidfinishload: (UIWebView *) webview{ @ " document.getelementsbyclassname (' detail_btns2 ') [0].remove (); " ; [WebView stringbyevaluatingjavascriptfromstring:str];}
4. Change HTML5 content in OC
-(void) Webviewdidfinishload: (UIWebView *) webview{ @ " document.getElementsByTagName (' H1 ') [0].innertext = ' Test text '; " ; [WebView stringbyevaluatingjavascriptfromstring:headerstr]; @" document.getElementById (' Xiazaiapp '). getElementsByTagName (' a ') [0].innertext = ' next egg '; " ; [WebView stringbyevaluatingjavascriptfromstring:downloadstr];}
Https://github.com/CoderJackyHuang/TextVeiw-Label-HTML-DEMO Uitextview and Uilabel How to load HTML content
Https://github.com/CoderJackyHuang/WebViewImgAutoFit WebView when loading images in HTML, handle pictures more than screen problems, let the picture adaptive screen
Https://github.com/CoderJackyHuang/WebViewJavascriptBridgeDemo
There is also a link attached, directly with the. http://www.jianshu.com/p/8ee9e168d680
iOS and HTML 5 interactive iOS load HTML5 call HTML method and modify HTML5 content