• Home
  • About
    • Young's Github Pages photo

      一日不作一日不食

    • About
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

iOS 브라우저에서 input type=button인 경우 click해도 focus가 생기지 않는 문제

19 Jul 2020

Reading time ~1 minute

  • iOS 브라우저에서 input type=button인 경우 click해도 focus가 생기지 않는다.
    • 브라우저별로 다르긴 하나 일반적으로 <button>을 클릭하면 button element로 focus가 이동을 한다.
    • 그러나 현재 iOS 브라우저(Safari, Chrome)에서는 focus가 가지지 않는다. (아래 mdn 참고)
  • iOS 브라우저에서도 click되었을 때 focus를 주기 위해서는 아래 코드처럼 강제로 focus를 줄 수 있다.
<script>
$(function() {
    $("#get-focused").click(function() {
        this.focus();
    });
});
</script>

<!-- 클릭하면 포커스가 생김  -->
<input type="button" value="focus test!" id="get-focused"></input>
<!-- 클릭해도 포커스가 생기지 않음 -->
<input type="button" value="focus test2" ></input>

0719_01

참고

  • StackOverflow
  • mdn - button element


TILiOS