最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Trigger iOS keyboard in web application on non-text element - Stack Overflow

matteradmin8PV0评论

I have a web application that uses a div that is not contentEditable. Instead, when the div is focused, I process key presses and insert / delete / update the innerHTML myself, essentially simulating a contentEditable div.

I don't care if it's necessarily with javascript, but I need a way to trigger the iOS keyboard from a web app.

I've tried floating an invisible text area over the div, and when it's focused, I hide the text area and shoot focus to the div. This works, but as soon as the non-contentEditable div is focused, the keyboard disappears. Note that this trick worked until iOS 5.

There has to be a way to trigger the iOS keyboard after user interaction in a web app, even if we're not on a text element. Any ideas?

I have a web application that uses a div that is not contentEditable. Instead, when the div is focused, I process key presses and insert / delete / update the innerHTML myself, essentially simulating a contentEditable div.

I don't care if it's necessarily with javascript, but I need a way to trigger the iOS keyboard from a web app.

I've tried floating an invisible text area over the div, and when it's focused, I hide the text area and shoot focus to the div. This works, but as soon as the non-contentEditable div is focused, the keyboard disappears. Note that this trick worked until iOS 5.

There has to be a way to trigger the iOS keyboard after user interaction in a web app, even if we're not on a text element. Any ideas?

Share Improve this question asked Dec 2, 2011 at 15:49 user1022241user1022241
Add a ment  | 

2 Answers 2

Reset to default 2

For a WebApp I need the keyboard too. I wanted it to work on iOS and so I created a little workaround.

The WebApp itself uses key listener to capture the pressed key (e.g. backspace for deleting elements).

I created a textfield with zero height, width and opacity. Don't use display:none; or visibility:hidden;. That causes iOS' Safari to not focusing the textfield.

function popKeyboard() {
    document.getElementById("dummyText").focus();
}

<input type="text" id="dummyText" style="width:0px; height:0px; opacity:none;" />
<input type="button" value="show keyboard" onclick="popKeyboard();" />

I hope that it helps you (even if you asked a year ago :))

The question has already been posted here: Manually triggering the iPhone/iPad/iPod keyboard from JavaScript

It looks like it is not possible I'm afraid!

Post a comment

comment list (0)

  1. No comments so far