如何使用JavaScript捕获iOS上的隐藏键盘事件

时间:2022-02-02 11:22:59

I need to do some resizing of the content of a web page when the hide keyboard button is pressed on an iPad virtual keyboard. Does anybody know which JavaScript event is launched when the keyboard is hidden?

当在iPad虚拟键盘上按下隐藏键盘按钮时,我需要对网页内容进行一些调整。有人知道隐藏键盘时启动了哪个JavaScript事件?

2 个解决方案

#1


17  

You can use the focusout event. It's like blur, but bubbles. It will fire when the keyboard closes (but also in other cases, of course). In Safari and Chrome the event can only be registered with addEventListener, not with legacy methods. Here is an example I used to restore a Phonegap app after keyboard dismissal.

您可以使用focusout事件。这就像模糊,但泡沫。键盘关闭时会触发(当然也会在其他情况下)。在Safari和Chrome中,事件只能使用addEventListener注册,而不能使用旧方法注册。以下是我在键盘解雇后恢复Phonegap应用程序的示例。

 document.addEventListener('focusout', function(e) {window.scrollTo(0, 0)});

Without this snippet, the app container stayed in the up-scrolled position until page refresh.

如果没有此代码段,则应用容器会保持在向上滚动的位置,直到页面刷新为止。

#2


3  

Here is a good place to start List of supported Javascript events on iPad

这是一个在iPad上启动支持的Javascript事件列表的好地方

which leads to http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

这导致http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

which does not list it.

没有列出它。

This one gives a work around iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari?

这个提供了围绕iPad Web App的工作:在Safari中使用JavaScript检测虚拟键盘?

#1


17  

You can use the focusout event. It's like blur, but bubbles. It will fire when the keyboard closes (but also in other cases, of course). In Safari and Chrome the event can only be registered with addEventListener, not with legacy methods. Here is an example I used to restore a Phonegap app after keyboard dismissal.

您可以使用focusout事件。这就像模糊,但泡沫。键盘关闭时会触发(当然也会在其他情况下)。在Safari和Chrome中,事件只能使用addEventListener注册,而不能使用旧方法注册。以下是我在键盘解雇后恢复Phonegap应用程序的示例。

 document.addEventListener('focusout', function(e) {window.scrollTo(0, 0)});

Without this snippet, the app container stayed in the up-scrolled position until page refresh.

如果没有此代码段,则应用容器会保持在向上滚动的位置,直到页面刷新为止。

#2


3  

Here is a good place to start List of supported Javascript events on iPad

这是一个在iPad上启动支持的Javascript事件列表的好地方

which leads to http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

这导致http://developer.apple.com/library/ios/#DOCUMENTATION/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5

which does not list it.

没有列出它。

This one gives a work around iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari?

这个提供了围绕iPad Web App的工作:在Safari中使用JavaScript检测虚拟键盘?