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;
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章