Automated HTML Focus Acquisition by IOS System

Time:2019-9-28

IOS system cannot automatically get HTML focus

// On normal browsers, JavaScript can be used to focus on an input box:
 var elem = document.getElementById(‘inputElementId’);
 elem.focus();
But on iOS phones, such code doesn’t work at all, only when focus is executed in functions that listen to user-initiated events.

var button = document.getElementById(‘btn’);
var inputElem = document.getElemntById(‘input-elem’);
button.addEventListener(‘click’, function(ev){
    inputElem.focus();
});

 $.subscribe(‘testevent’,function(ev){
          $(‘#test’).focus();
     });
    $(‘#btn’).click(function(ev){
         $.publish(‘testevent’)
     });