Yoav Schwartz
Yoav Schwartz

Reputation: 2027

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.

Upvotes: 4

Views: 190

Answers (2)

Vignesh
Vignesh

Reputation: 10251

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.

Upvotes: 1

mityaika07
mityaika07

Reputation: 653

if you can change html page - you can put javaScript callBack on chack change, and handle it in

- (BOOL)webView:(CustomWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

Upvotes: 0

Related Questions