Search code examples
iosobjective-cuiwebviewuiwebviewdelegate

Capturing information from a UIWebView


I have a UIWebView in my app that parses HTML from a server and presents it. My challenge is that this HTML has a checklist in it, and I would like to capture what the user checks and unchecks the next time I load the same HTML.

Is there anyway to capture the click on the checkbox? Any ideas on how to do it?

Thanks in advance.


Solution

  • It can be done with the help of java script. It involves multiple steps

    1. Add a listener to document for the event 'CheckboxStateChange'.
    2. check the event's target id is the check id of the checkbox you wanted. if so capture the value in a js variable.
    3. Now load a iframe with a specific URL prefix say myevent://checkbox?id:value
    4. If a iframe is loaded your web view will trigger shouldStartLoadWithRequest method. You can check url scheme from the request object passed. If it is "myevent" you can parse the URL string to store the appropriate value.
    5. Next time when the page is loaded you can set the value by injecting javascript with the value you have stored.