4

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.

Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43

2 Answers2

1

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.
Vignesh
  • 10,205
  • 2
  • 35
  • 73
  • I think I understand, I need to add javascript to the file and use the event to trigger a link which contains the ID of the check? Would you mind writing a small code sample how you imagine the delegate call and javascript function look like. I understand the concept but I'm not sure how it's possible to do it – Yoav Schwartz Nov 04 '14 at 13:35
  • I'm marking this as solved since I think it gave me and any other person looking at this enough information to solve the problem, however since there is interest in this question besides mine I think it's nice if theres some sample simple code in the answer. When I finish making it and if theres still no code I will hopefully add it. – Yoav Schwartz Nov 04 '14 at 13:58
  • @YoavSchwartz, It is definitely possible. As I have implemented a similar thing myself. Yes, I would add a small code snippet when my time permits. – Vignesh Nov 05 '14 at 06:03
0

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;
}
mityaika07
  • 652
  • 5
  • 14