从javascript显示android键盘 [英] Show android keyboard from javascript

查看:161
本文介绍了从javascript显示android键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在导航到该页面后在移动浏览器(例如Android)上显示键盘。
我已经看到了一些解决方法:

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:

通过javascript在手机上显示虚拟键盘

我可以触发Android软键盘通过javascript(没有phonegap)打开吗?

当字段为.focus()时使用javascript 显示Android的软键盘

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

但所有这些示例仅在用户点击某处时才有效。它允许从 click()中触发 focus()。有人知道是否有任何方法可以做同样的事情,但没有用户点击?

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?

我试图以编程方式触发点击但它也无法正常工作。 http://jsfiddle.net/alex_myronov/e5JcP/10/

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

推荐答案

我设法通过调用输入的focus()方法成功打开虚拟键盘。

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

它在我的应用程序中同时适用于android 2.3和4.1。

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 completly rendered before you call focus().

我的应用程序正在使用jquery mobile,当 pageshow事件

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?

这篇关于从javascript显示android键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆