0

브라우저가 CORS가 포함 된 기본 JavaScript XMLHttpRequest 객체를 지원하는지 어떻게 확인합니까? 나는 IE 8에서 다음 그러나하고, 나는 단지 이해 XDomainRequest을 지원하는 IE 8에서 테스트입니다 :브라우저가 전체 CORS 지원을 사용하는 XMLHttpRequest를 지원하지 않는지 확인합니다.

typeof window.XMLHttpRequest 
"object" 

나는 undefined이 될 것이라고 생각했을 것이다. 기본적으로 브라우저에서 CORS를 지원하는 XMLHttpRequest을 지원하는지 어떻게 확인할 수 있습니까?

반전해야합니까?

I 이것을 사용
if(type window.XDomainRequest === 'object') { 
    // Assume the browser does not support XMLHttpRequest with CORS 
} 

답변

1

, 1 2 XDomainRequest 통해 지원 고르 수단 XMLHttpRequest를 지원 고르 수단, 0은 CORS 지원되지 수단

var corsSupportLevel = null;  
function supportsCorsInternal() { 

       if (corsSupportLevel !== null) return corsSupportLevel; 

       var xhr = new XMLHttpRequest(); 
       if (typeof xhr.withCredentials !== 'undefined') { 
        // Supports CORS 
        corsSupportLevel = 1; 
       } else if (typeof XDomainRequest !== "undefined") { 
        // IE 
        corsSupportLevel = 2; 
       } else { 
        corsSupportLevel = 0; 
       } 
       return corsSupportLevel; 
      }