iOS and HTML 5 interactive iOS load HTML5 call HTML method and modify HTML5 content

Source: Internet
Author: User

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 MethodswebViewDidFinishLoad:
    • 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

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.