Javascript focus () doesn't work in UIWebView if another element already had focus

I am facing Javascript issue in UIWebView:

I have two input elements in my webpage like #focusone and #focustwo

<input type="text" id="focusone" size="35"></input><br/><br/>
<input type="text" id="focustwo" size="35"></input>

      

In my script, I want to programmatically set focus to #focusone.

function setFocus() {
  $("#focusone").focus();
}

      

(The problem occurs with and without jQuery)

This works as long as #focustwo has no focus. If #focustwo (or any other element where the keyboard pops up) was already in focus, the JavaScripts' focus () method will set focus to #focusone but refuse to open the keyboard or show a small vertical bar inside the input element, indicating that the input element actually has focus ... If no other element that opens the keyboard has focus, everything works as intended.

The problem only appears in UIWebView - everything works in Safari.

Has anyone else encountered this problem and found any workarounds?

+3


source to share





All Articles