Reputation: 388
I have successfully injected javascript into my UIWebView and successfully changed values in text fields that I wanted to using the method below. Now I want to automatize the click in the HTML Form button, but to no success, it seems the button is disabled until it receives a touch event and only on the second touch event does it submits the HTML Form, is this why the JS 'click()' method I inject does not work? How can I make it work?
The method of injection I use is described in this page
I've used this: [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('ctl00_SPWebPartManager1_g_cb264700_1517_426f_926d_3ca40934a6fd_ctl00_EditModePanel1_btnLogin.click();');"];
And also:
[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function x_LogBtn() { "
"var field = document.getElementById('ctl00_SPWebPartManager1_g_cb264700_1517_426f_926d_3ca40934a6fd_ctl00_EditModePanel1_btnLogin');"
"field.click();"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
[webView stringByEvaluatingJavaScriptFromString:@"x_LogBtn();"];
With no success, anyone can give me some light on the subject? Thanks!
Upvotes: 0
Views: 2358
Reputation: 22305
I can't tell you why the click doesn't work -- though it could easily be an intentional security restriction on the part of the iOS dev team -- but there may be another way to solve your problem.
My question for you is why you're doing it this way. If you want to submit form data on behalf of a user out to a server somewhere, why not just send the information directly using a POST request to the server? When you get the response you can either parse it and run some other code or you can just throw the HTML into a UIWebView. It eliminates all of the javascript hackery you're doing and produces a result that will be much more pleasing to the user, I'm sure.
Upvotes: 1