'window.location.hash.incloses'를 사용하면 IE11에서 "Object가 속성 또는 메서드 'incloses'를 지원하지 않습니다.
URL이 포함되어 있는지, 포함되어 있는지 확인 중입니다.?
창에서 해시 팝 상태를 제어하기 위해 저장됩니다.다른 브라우저들은 모두 문제가 없고 IE만 문제가 있습니다.
이런 방식으로 로드하려고 하면 디버거에서 다음과 같은 오류가 발생합니다.
개체가 속성 또는 메서드를 지원하지 않습니다.'
includes
'
팝업 상태를 통해 페이지를 로드해도 오류가 발생하지 않습니다.
$(document).ready(function(e) {
if(window.location.hash) {
var hash;
if(window.location.hash.includes("?")) {
alert('I have a ?');
hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?'));
}else {
hash = window.location.hash;
};
if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){
$(hash+'Content').addClass('pageOn').removeClass('pageOff');
}else {
$('#homeContent').addClass('pageOn').removeClass('pageOff');
};
} else {
$('#homeContent').addClass('pageOn').removeClass('pageOff');
}
$(window).on('popstate', function() {
var hash;
if(window.location.hash.includes("?")) {
hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?'));
}else {
hash = window.location.hash;
};
if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){
$(this).navigate({target: $(hash+'Content')});
if(window.location.hash.includes("?")) {
}else{
location.href = location.href+'?';
}
}else {
$(this).navigate({target: $('#homeContent')});
};
});
});
MDN 참고 페이지에 의하면,includes
Internet Explorer에서 지원되지 않습니다.가장 간단한 대안은 다음을 사용하는 것입니다.indexOf
, 다음과 같이:
if(window.location.hash.indexOf("?") >= 0) {
...
}
IE11은 String.prototype.을 구현하는데 공식 Polyfill을 사용하지 않는 이유는 무엇입니까?
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
출처 : 폴리필 출처
추가하기import 'core-js/es7/array';
나에게polyfill.ts
그 문제를 해결해 주었어요.
Angular 프로젝트와 비슷한 문제가 있었습니다.폴리필.ts에서 다음 두 가지를 모두 추가해야 했습니다.
import "core-js/es7/array";
import "core-js/es7/object";
다른 모든 IE 11 기본값을 활성화하는 것 외에도.(각형을 사용하는 경우 polyfills.ts의 주석 참조)
이러한 가져오기를 추가한 후 오류가 사라졌고 내 Object 데이터가 의도한 대로 채워졌습니다.
Internet Explorer에서와 같이 javascript 메서드 "include"가 지원되지 않으므로 아래와 같은 오류가 발생합니다.
도수형FilteringSelectTypeError: 개체가 '포함' 속성이나 메서드를 지원하지 않습니다.
그래서 아래와 같이 자바스크립트 문자열 방식을 "inclubs"에서 "indexOf"로 변경하였습니다.
//str1 doesn't match str2 w.r.t index, so it will try to add object
var str1="acd", str2="b";
if(str1.indexOf(str2) == -1)
{
alert("add object");
}
else
{
alert("object not added");
}
전부터 사용했습니다.Lodash
원주민과 정말 비슷하네요.
저는 ReactJ를 사용하고 있고 사용하고 있습니다.import 'core-js/es6/string';
초입에index.js
내 문제를 해결하기 위해서 입니다.
저도 사용하고 있습니다.import 'react-app-polyfill/ie11';
IE11에서 React 실행을 지원합니다.
반응식 앱 폴리필
이 패키지에는 다양한 브라우저용 폴리필이 포함되어 있습니다.여기에는 Create React App 프로젝트에서 사용하는 최소 요구사항과 일반적으로 사용되는 언어 기능이 포함되어 있습니다.
https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md
이 질문과 그에 대한 답변은 비록 일부에서는 기본 프로토타입을 변형해서는 안 된다고 하지만, SO의 도움을 받아 제 자신만의 솔루션으로 이끌었습니다.
// IE does not support .includes() so I'm making my own:
String.prototype.doesInclude=function(needle){
return this.substring(needle) != -1;
}
그 다음에 전부 교체했습니다..includes()
와 함께.doesInclude()
내 문제는 해결됐습니다.
언급URL : https://stackoverflow.com/questions/31119300/using-window-location-hash-includes-throws-object-doesnt-support-property-or
'sourcecode' 카테고리의 다른 글
입력이 유형 확인란인지 jQuery 체크? (0) | 2023.10.06 |
---|---|
클라이언트에 쿠키가 설정되지 않을 수 있는 이유는 무엇입니까? (0) | 2023.10.06 |
특정 버전으로 Git에서 npm 설치 (0) | 2023.10.06 |
PHP-FPM이 제대로 실행되고 있는지 확인하는 방법은? (0) | 2023.10.06 |
jQuery를 사용하여 cs ":After" 선택기에 액세스합니다. (0) | 2023.10.06 |