ajaxFileUpload报错:无法获取未定义或 null 引用的属性“version”

项目中一个页面,在chrome和IE11下能正常运行,但在IE10及其以下版本中报错,报错信息为无法获取未定义或 null 引用的属性“version”


报错的js代码如下:

if (window.ActiveXObject) {
    if (jQuery.browser.version == "9.0") { // 报错位置,无法获取未定义或 null 引用的属性“version”
        io = document.createElement('iframe');
        io.id = frameId;
        io.name = frameId;
    } else if (jQuery.browser.version == "6.0" 
                || jQuery.browser.version == "7.0" 
                || jQuery.browser.version == "8.0") {
              var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
              if (typeof uri == 'boolean') {
                  io.src = 'javascript:false';
              } else if (typeof uri == 'string') {
                   io.src = uri;
              }
     }
}

debug发现,在IE下jquery.browser为undefined,查询后发现jQuery 从 1.9 版开始,移除了jquery.browser 和 jquery.browser.version ,取而代之的是 $.support 。运行出错的页面使用的jquery版本为2.1.1,所以在IE浏览器下运行出错。

对修改ajaxFileUpload代码,使用navigator.userAgent来进行IE浏览器版本判断,修改后的代码如下:

if (window.ActiveXObject) {
    var ieVersion = navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE","");
    if (ieVersion == "9.0" || ieVersion == "10.0") { //jQuery.browser.version == "9.0"
        io = document.createElement('iframe');
        io.id = frameId;
        io.name = frameId;
    } else if (ieVersion == "6.0" 
        || ieVersion == "7.0" 
        || ieVersion == "8.0") {
        var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
        if (typeof uri == 'boolean') {
            io.src = 'javascript:false';
        } else if (typeof uri == 'string') {
            io.src = uri;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值