search

Home  >  Q&A  >  body text

javascript - HTML5 initial pop-up keypad

Please tell me, God, let the small keyboard of the HTML5 page pop up when the page first comes in.
ps: There is input in the page!
ps: Don’t tell me what focus to get. I’ve tried it all but it doesn’t seem to work. It doesn’t work on Android or Apple. Unless you click on it. . .

PHP中文网PHP中文网2762 days ago920

reply all(1)I'll reply

  • 迷茫

    迷茫2017-06-15 09:24:43

    Making the small keyboard pop up can only be activated through input`focus, so when you enter the page, just let it automatically focus`.
    You can use the autofocus attribute in html5. Usually this setting is enough.

    <input type="text" name="fname" autofocus="autofocus" />

    There is no problem on Android, but Safari on the mobile side does not support the autofocus attribute by default, and only events triggered by the user can make focus methods take effect, so we can only simulate a fake one. autofocus:

    <input type="text" id="focus" />
    document.addEventListener('touchstart',function(e){
      e.preventDefault();
      console.log('touched!');
      document.getElementById('focus').focus();
    });

    Online Demo

    reply
    0
  • Cancelreply