티스토리 뷰

728x90

죽일놈의 ie.. StatCounter 에서 브라우저 점유율을 살펴보면 2021년 3월기준 0.73%이다.

왜 아직도 공공기관 사람들은 이걸 고집하는지...답답할 노릇이다.

 

크로스 브라우징을 위해 사용하는 jQuery 에서도 이런 오류가 나는거보면 진짜 버려야 할때가 되지 않았나 싶다.

(jQuery 3.6.0이 현재 2021 04월 기준 최신인거 같은데 여기서만 나는지는 모르겠다..언제 부터 안되는건지는 잘 모르겠음)

 

String.prototype.includes()가 ie에서는 지원하지 않으니 jQuery 스크립트가 실행되지 않는다는 오류이다.

 

해결방법으로는 String String.prototype.includes() 의 Polyfill을 추가해주면 된다.

if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;
    }

    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;
    }
  };
}

참고

developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/includes

 

String.prototype.includes() - JavaScript | MDN

String.prototype.includes() includes() 메서드는 하나의 문자열이 다른 문자열에 포함되어 있는지를 판별하고, 결과를 true 또는 false 로 반환합니다. str.includes(searchString[, position]) searchString 이 문자열에

developer.mozilla.org

 

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함