Javascript 检测浏览器是否不支持完全支持CORS的XMLHttpRequest

Javascript 检测浏览器是否不支持完全支持CORS的XMLHttpRequest,javascript,internet-explorer-8,xmlhttprequest,xdomainrequest,Javascript,Internet Explorer 8,Xmlhttprequest,Xdomainrequest,如何检查浏览器是否支持带有CORS的本机JavaScript XMLHttpRequest对象?我在IE 8中进行测试,据我所知,IE 8只支持XDomainRequest,但在IE 8中执行以下操作: typeof window.XMLHttpRequest "object" 我原以为那是未定义的。基本上,我如何检测浏览器是否支持CORS支持的完整XMLHttpRequest 我应该反过来做吗 if(type window.XDomainRequest === 'object') {

如何检查浏览器是否支持带有CORS的本机JavaScript XMLHttpRequest对象?我在IE 8中进行测试,据我所知,IE 8只支持
XDomainRequest
,但在IE 8中执行以下操作:

typeof window.XMLHttpRequest
"object"
我原以为那是
未定义的
。基本上,我如何检测浏览器是否支持CORS支持的完整
XMLHttpRequest

我应该反过来做吗

if(type window.XDomainRequest === 'object') {
    // Assume the browser does not support XMLHttpRequest with CORS
}

我使用它,1表示XMLHttpRequest支持cors,2表示cors通过XDomainRequest得到支持,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;
            }

我使用它,1表示XMLHttpRequest支持cors,2表示cors通过XDomainRequest得到支持,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;
            }