1

I am developing a custom browser for iOS something like Mogok. I need to change the default keyboard when user taps any text input on UIWebView.

I tried this and this with no luck. I have a workaround for buttons but this does not work for textinput and textarea.

My js code is as under for this:

NSString *jsCode = @"function setClickEvent() {for ( i = 0; i < document.all.length; i++) { var obj = document.all[i]; obj.addEventListener('click',function(){window.location = "fake://myApp/something_happened:param1:param2:param3";})}} setClickEvent();";
[self._webView stringByEvaluatingJavaScriptFromString:jsCode];

Is there any other way to achieve this? My only requirement get the notification when user taps on textinput or textarea.

halfer
  • 19,824
  • 17
  • 99
  • 186
TechBee
  • 1,897
  • 4
  • 22
  • 46
  • You can see my answer in the other question: http://stackoverflow.com/questions/19961369/how-the-default-keyboard-comes-up-when-user-taps-in-uiwebview/20037193#20037193 – dcorbatta Nov 19 '13 at 20:07

1 Answers1

1

I'd suggest you add something like this, to see if your javascript code runs as expected:

NSString *jsCode = @"
"try{"
"    for ( i = 0; i < document.all.length; i++) {" 
"        var obj = document.all[i];"
"        obj.addEventListener('click',function(){"
"            window.location = \"fake://myApp/something_happened:param1:param2:param3\";"
"        });"
"    }"
"}"
"catch (exc){"
"    return \"caught exception: \" + exc.toString();"
"}";
NSString result = [self._webView stringByEvaluatingJavaScriptFromString:jsCode];
NSLog(@"%@", result);

You can add whatever logging you need in your return (e.g: have a string and keep appending to it).

By the way, there's a getElementByTagName method for javascript, which can be used to fetch only elements of certain type (in your case <textarea> and <input> - you'll also need to check the attributes/type to make sure it's a textfield)

alex-i
  • 5,406
  • 2
  • 36
  • 56