1

I have a very simple page which is loaded inside the UIWebView using the following code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSURL *url = [NSURL URLWithString:@"http://www.highoncoding.com/home/test"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [self.webView loadRequest:request];

}

And I am trying to focus on the TextBox "txtName" using the following code:

- (void)webViewDidFinishLoad:(UIWebView *)wv
{
    NSLog(@"webViewDidFinished");

    [wv stringByEvaluatingJavaScriptFromString:@"if(document.getElementById('txtName') != null) { document.getElementById('txtName').focus() }"];
}

Although it does find the TextBox but it never focus on the TextBox and the keyboard never pops up.

azamsharp
  • 19,710
  • 36
  • 144
  • 222
  • 1
    It looks like this is not possible. See http://stackoverflow.com/questions/6287478/mobile-safari-autofocus-text-field and http://stackoverflow.com/questions/8001052/how-to-preselect-contenteditable-field-in-uiwebview-ios5 – Lawrence Barsanti Jul 19 '12 at 01:01
  • I guess the answer is that it is not possible! – azamsharp Jul 19 '12 at 01:04
  • Looks like this is possible now: http://stackoverflow.com/questions/4442811/how-can-i-get-a-uiwebview-to-focus-on-a-form-input-and-bring-up-the-keyboard – Kartik Ayyar Jan 10 '14 at 14:20

0 Answers0