如何在iOS上的移动Web浏览器中使键盘触发器调整事件大小?

时间:2022-08-26 22:49:00

I am writing a single-page web app in HTML5/Javascript (basically a telnet terminal). It is using text input a lot, so most of the time the software keyboard will be visible on touch devices.

我正在用HTML5 / Javascript(基本上是一个telnet终端)编写一个单页的Web应用程序。它使用了很多文本输入,因此大多数时候软件键盘在触摸设备上都可见。

It seems that on iOS (iPad with latest iOS) showing the software keyboard does not resize the page and does not trigger a resize event (in Javascript), causing half of my app's output to be off screen.

似乎在iOS(具有最新iOS的iPad)上显示软件键盘没有调整页面大小并且不会触发调整大小事件(在Javascript中),导致我的应用程序输出的一半在屏幕外。

Is there any way of changing this default behavior on iOS (maybe with a meta tag, or the like) or is there some other event I can use? I would like to receive a resize or other event whenever the keyboard is shown / hidden and thus the viewport size chages.

有没有办法在iOS上更改此默认行为(可能带有元标记等),还是有其他一些我可以使用的事件?每当键盘显示/隐藏时,我希望收到调整大小或其他事件,因此视口大小会变化。

1 个解决方案

#1


-1  

How about you try .focus()? If your input gets focused you can trigger resize:

你怎么试试.focus()?如果你的输入被聚焦,你可以触发调整大小:

$('#input').focus(function() {
  //do resize

}); 

More info on .focus() http://api.jquery.com/focus/

有关.focus()的更多信息http://api.jquery.com/focus/

#1


-1  

How about you try .focus()? If your input gets focused you can trigger resize:

你怎么试试.focus()?如果你的输入被聚焦,你可以触发调整大小:

$('#input').focus(function() {
  //do resize

}); 

More info on .focus() http://api.jquery.com/focus/

有关.focus()的更多信息http://api.jquery.com/focus/