Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open iOS keyboard on page load

I have an html web app and I want the keyboard to open when I load my page, I've tried:

<textarea class="form-control" autofocus="autofocus"></textarea>

but all that does is focus the textarea and makes it show up once I touch the page, rather then just automatically on page load.

I heard that it was impossible to do this without some type of user interaction in JavaScript alone. If this is true, are there any plugins out there that might do this?

Hope this makes sense, thanks!

like image 356
NotToBrag Avatar asked Nov 22 '14 23:11

NotToBrag


1 Answers

Unfortunately, autofocus isn't supported by mobile Safari due to usability reasons. I've seen people try different work arounds, including simulating a click/focus on the element in question. I've never been able to get it to work though, on mobile Safari at least.

$(function(){
  $('#my-textarea').focus().click();
})
like image 83
Bart Jedrocha Avatar answered Oct 19 '22 11:10

Bart Jedrocha