开发者

How can I focus on an input field when a phonegap page loads?

开发者 https://www.devze.com 2023-02-21 11:26 出处:网络
I would like to focus on a text input in a PhoneGap application when the page loads. I have tried the MooTools version $(\'entry\').focus(); and document.getElementById(\'entry\').focus() when the DOM

I would like to focus on a text input in a PhoneGap application when the page loads. I have tried the MooTools version $('entry').focus(); and document.getElementById('entry').focus() when the DOM is ready.

This works fine when the HTML page is viewed in a normal web browse开发者_运维知识库r, but in the iPhone simulator running PhoneGap, it doesn't work.

Is there a way to focus on a form field for iPhones that forces the virtual keyboard to appear?


As of iOS 6, the UIWebView class has a property called "keyboardDisplayRequiresUserAction". If you want to programmatically focus text form elements, set this to false via your phonegap config.xml:

<preference name="KeyboardDisplayRequiresUserAction" value="false" />

The default value is true.

More here: http://community.phonegap.com/nitobi/topics/calling_focus


As far as I know, this is an intentional limitation of WebKit on both iPhone and Android; only a user touch action can trigger a keyboard. I'm still trying to concoct a workaround, but I'm not very optimistic.

0

精彩评论

暂无评论...
验证码 换一张
取 消