如何使用JavaScript捕获iOS上的隐藏键盘事件 [英] How to capture the hide keyboard event on iOS using JavaScript

查看:779
本文介绍了如何使用JavaScript捕获iOS上的隐藏键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

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

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.

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

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

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

这篇关于如何使用JavaScript捕获iOS上的隐藏键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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