最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Show android keyboard from javascript - Stack Overflow

programmeradmin3浏览0评论

I want to be able to show keyboard on mobile browser (e.g. Android) after navigating to the page. I have already seen some workarounds:

Show virtual keyboard on mobile phones in javascript

Can I trigger Android soft keyboard to open via javascript ( without phonegap )?

Showing Android's soft keyboard when a field is .focus()'d using javascript

But all of these examples work only if user tap somewhere. It allows to trigger focus() from within the click(). Does someone know if there any way to do the same thing but without user clicking?

I've tried to trigger click programmatically but it also not working. /

I want to be able to show keyboard on mobile browser (e.g. Android) after navigating to the page. I have already seen some workarounds:

Show virtual keyboard on mobile phones in javascript

Can I trigger Android soft keyboard to open via javascript ( without phonegap )?

Showing Android's soft keyboard when a field is .focus()'d using javascript

But all of these examples work only if user tap somewhere. It allows to trigger focus() from within the click(). Does someone know if there any way to do the same thing but without user clicking?

I've tried to trigger click programmatically but it also not working. http://jsfiddle/alex_myronov/e5JcP/10/

Share Improve this question edited May 23, 2017 at 11:52 CommunityBot 11 silver badge asked Jan 10, 2014 at 21:32 alex.mironovalex.mironov 2,9526 gold badges29 silver badges42 bronze badges 1
  • EDIT: sorry misread the question.stackoverflow./a/12113168/2558344 Everything you would need is there^. – Aashir Commented Jan 10, 2014 at 21:37
Add a ment  | 

2 Answers 2

Reset to default 2

My current answer to this is no, can't be done. The script that calls focus() click() on an input needs to be running with user context, ie. triggered by a user interaction. After fairly dedicated fiddling, I've found no way round this.

I managed to successfully open the virtual keyboard by just calling focus() method of the input.

It works in my app both on android 2.3 and 4.1.

I think the trick is that you have to wait untill the page is pletly rendered before you call focus().

My app is using jquery mobile and I call focus() when the pageshow event is triggered:

$("#myPage").on("pageshow", function( event ) {
        $("#myPage").find('input:first').focus();
} );

Or maybe it's working because I'm in a phonegap app?

发布评论

评论列表(0)

  1. 暂无评论