这些ActiveXObject和XMLHttpRequest检查是否适用于IE6以外的任何其他浏览器? [英] Will these ActiveXObject and XMLHttpRequest checks apply for any other browser than IE6?

查看:78
本文介绍了这些ActiveXObject和XMLHttpRequest检查是否适用于IE6以外的任何其他浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE10中为plUpload插件遇到了一个奇怪的错误,我发现如果在我们的项目中删除此代码,一切都会正常进行.谁能确切告诉我它的作用以及是否可以安全删除?看起来它仅适用于IE6?我说的对吗?

I got a weird error in IE10 for plUpload plugin, and I found that if I remove this code in our project everything works fine. Can anyone tell me exactly what this does and if it's safe to remove? It looks like it only applies for IE6? Am I right?

var progids = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
var progid = null;


if (typeof ActiveXObject != "undefined") {
var ie7xmlhttp = false;
if(typeof XMLHttpRequest == "object") {
    try {
        var o = new XMLHttpRequest();
        ie7xmlhttp = true;
    } catch (e) {
    }
}
if(typeof XMLHttpRequest == "undefined" || !ie7xmlhttp) {
    XMLHttpRequest = function() {
        var xmlHttp = null;
        if(!BlocAjax.noActiveX) {
            if(progid != null) {
                return new ActiveXObject(progid);
            }
            for(var i=0; i<progids.length && xmlHttp == null; i++) {
                try {
                    xmlHttp = new ActiveXObject(progids[i]);
                    progid = progids[i];

                }catch(e){}
            }
        }
        if(xmlHttp == null && MS.Browser.isIE) {
            return new .IFrameXmlHttp();
        }
        return xmlHttp;
    };
}

}

推荐答案

是的,我相信还有其他浏览器.您显示的检查试图通过查找具有ActiveX支持(IE *)但不支持XMLHttpRequest(IE6-)的浏览器来检测IE.但是,如果想将ie7xmlhttp标志初始化为null或未定义,那么由于 if(typeof XMLHttpRequest =="undefined" ||!ie7xmlhttp){在这种情况下将是正确的.

Yes, I believe there are other browsers. The checks you show are trying to detect IE by looking for browsers with ActiveX support (IE*), but no XMLHttpRequest support (IE6-). However if the ie7xmlhttp flag is presumably initialized to null or undefined, then any non-IE browser that doesn't have XMLHttpRequest support will be treated similarly since if(typeof XMLHttpRequest == "undefined" || !ie7xmlhttp) { will be true in those cases.

因此,几乎没有XMLHttpRequest支持的任何旧浏览器将落入 if 块中,该块试图使XMLHttpRequest API趋于平滑.并不是说有很多人在使用它们,但是我敢肯定他们在那里.(例如,特别是FF,Opera,Safari的旧版本……鲜为人知的移动浏览器……这类东西.)

Thus, pretty much any older browser w/out XMLHttpRequest support will fall into the if block that tries to shim the XMLHttpRequest API. Not that there are a lot of people using them, but I'm sure they're out there. (e.g. particularly old versions of FF, Opera, Safari... lesser known mobile browsers maybe... that sort of thing.)

BTW, Microsoft的XMLHttpRequest文档推荐此代码段用于x平台XMLHttpRequest构建,我建议:

BTW, Microsoft's XMLHttpRequest documentation recommends this code snippet for x-platform XMLHttpRequest construction, which I recommend:

function getXMLHttpRequest() 
{
    if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
    }
    else {
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
            return null;
        }
    }
}

这篇关于这些ActiveXObject和XMLHttpRequest检查是否适用于IE6以外的任何其他浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆