0

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!

1
  • I just wanted to say, I have the same question today, three years later. Commented Apr 29, 2013 at 21:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I first tried to go with the POST request but it wasn't so forward as I expected and I want to resolve this quickly, I'll try to send a touch-event to workaround this issue while I don't figure how to send a correct POST... Btw, I have asked for help about the POST issue before (stackoverflow.com/questions/4298456/…) if you can give me some pointers on the subject I'll be most appreciated! :p I think the website uses ASP.NET and it generates some nasty html/javascript... :\
I responded over there with the most likely culprit. It should solve your problem.
Sometimes you have things like session and cookies and you have no access to the web server. But you need to extend a simple functionality on the page. So this is a handy way to go about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.