无效的调用对象IE 11 XML数组的长度(getElementsByTagName)

时间:2016-01-26 13:38:15

标签: javascript xml internet-explorer-11

我不确定我应该如何在IE中解决此无效的调用对象错误。似乎IE不允许我在其他函数中使用全局表情符号?

    var emoticon = new Array();
    var emote_page;
    var emote_pages;

    getPaginateEmoticons(1);

    function navigateEmoticons(page){
        var i = ((page - 1) * 37);
        var p_emotes = page * 37;
        var emotes_div = document.getElementById('emoticons');

        if(page == 1){
            document.getElementById('previous_emo_p').style.display = 'none';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page > 1 && page < emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page == emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'none';
        }
        emotes_div.innerHTML = '';
        while(i < p_emotes && i <= emoticon.length){
            i++;
            emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
            emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
        }
        emote_page = page;
    }

    function getPaginateEmoticons(page){
        var emotes_div = document.getElementById('emoticons');
        var emote_pages_sel = document.getElementById('emote_page');
        var i;

        function handler(){
            if(this.status == 200 && this.responseXML != null){
                emoticon = this.responseXML.getElementsByTagName('file');
                emote_pages = Math.floor(emoticon.length / 37);
                emote_page = page;
                for(i = 0; i < 37; i++){
                    if(i == 1)
                        emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '" selected="selected">Page ' + i + '</option>');
                    else if(i <= emote_pages && i > 1)
                        emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '">Page ' + i + '</option>');  
                    emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
                    emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
                }
                document.getElementById('previous_emo_p').style.display = 'none';
                document.getElementById('loadingIcon').style.display = 'none';
            }
            else{
                // something went wrong
            }
        }

        var client = new XMLHttpRequest();
        client.onload = handler;
        client.open("GET", "resources/emo_catalog.xml");
        client.send();
    }

while(i < p_emotes && i <= emoticon.length){行发生无效的调用对象错误。任何帮助将不胜感激。

4 个答案:

答案 0 :(得分:1)

我不知道IE 11,但是较低版本不支持@Route("/{id}_apartments.html", name="neighborhood_detail"), requirements={"id"="[a-zA-Z0-9_]+"}) ,但需要写一些像var client = new XMLHttpRequest();这样的想法。 这可能是ActiveXObject问题。

1

可能的问题编号function getXmlHttp(){ var xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } return xmlhttp; }

2

IE 8说Object不支持此属性

答案 1 :(得分:0)

代码就在这里。我不知道它是否有效,因为没有文件可供下载和解析。让我知道它是否有效

var emoticon = new Array();
var emote_page;
var emote_pages;

/*
 document.addEventListener("DOMContentLoaded", function() { // show error addEventListener is not supported
    getPaginateEmoticons(1);
});
*/

/* Cahge here *****************************************/
if (document.addEventListener){
  document.addEventListener("DOMContentLoaded", function() {
    getPaginateEmoticons(1); });
} 
else if (document.attachEvent){
  document.attachEvent("DOMContentLoaded", function() {
    getPaginateEmoticons(1); });
}
/****************************************************/   

function navigateEmoticons(page){
    var i = ((page - 1) * 37);
    var p_emotes = page * 37;
    var emotes_div = document.getElementById('emoticons');

    if(page == 1){
        document.getElementById('previous_emo_p').style.display = 'none';
        document.getElementById('next_emo_p').style.display = 'inline';
    }
    else if(page > 1 && page < emote_pages){
        document.getElementById('previous_emo_p').style.display = 'inline';
        document.getElementById('next_emo_p').style.display = 'inline';
    }
    else if(page == emote_pages){
        document.getElementById('previous_emo_p').style.display = 'inline';
        document.getElementById('next_emo_p').style.display = 'none';
    }
    emotes_div.innerHTML = '';
    while(i < p_emotes && i <= emoticon.length){
        i++;
        emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
        emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
    }
    emote_page = page;
}

function getPaginateEmoticons(page){
    var emotes_div = document.getElementById('emoticons');
    var emote_pages_sel = document.getElementById('emote_page');
    var i;

    function handler(){
        if(this.status == 200 && this.responseXML != null){
            emoticon = this.responseXML.getElementsByTagName('file');
            emote_pages = Math.floor(emoticon.length / 37);
            emote_page = page;
            for(i = 0; i < 37; i++){
                if(i == 1)
                    emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '" selected="selected">Page ' + i + '</option>');
                else if(i <= emote_pages && i > 1)
                    emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '">Page ' + i + '</option>');  
                emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
                emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
            }
            document.getElementById('previous_emo_p').style.display = 'none';
            document.getElementById('loadingIcon').style.display = 'none';
        }
        else{
            // something went wrong
        }
    }
/* Cahge here *****************************************/
var client = new XMLHttpRequest(); /*I think bad, but no error show*/
/****************************************************
    client.onload = handler;
    client.open("GET", "resources/emo_catalog.xml");
    client.send();

}

答案 2 :(得分:0)

此代码在IE8中接收xml文档。

var emoticon = new Array();
var emote_page;
var emote_pages;
function getPaginateEmoticons(page){
var emotes_div = document.getElementById('emoticons');
var emote_pages_sel = document.getElementById('emote_page');
var i;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
myFunction(xhttp);
}
};

xhttp.open("GET", "http://victoria.ru/a.xml", true);
xhttp.send();

function myFunction(xml) {
var xmlDoc = xml.responseXML; alert(xmlDoc);
emoticon = xmlDoc.getElementsByTagName("file")[0].childNodes[0].nodeValue;   

emote_pages = Math.floor(emoticon.length / 37);
emote_page = page;

for(i = 0; i < 37; i++){
/* ... HERE ALSO ERRORS */ 
/*
if(i == 1) emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '" selected="selected">Page ' + i + '</option>');
else if(i <= emote_pages && i > 1) emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option value="' + i + '">Page ' + i + '</option>');  
emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');

*/
}

document.getElementById('previous_emo_p').style.display = 'none';
document.getElementById('loadingIcon').style.display = 'none';

}
}

答案 3 :(得分:0)

我最终必须将内容放入一个字符串并将其存储在隐藏的分割元素中,然后每次迭代时我都必须将字符串转换回数组。有点失败了使用XML文件的整个目的:(

var emoticon = new Array();
var emote_page;
var emote_pages;

function navigateEmoticons(page){
    page = page - 1;
    page = page + 1;

    if(!page)
        page = 1;

    var i = (page - 1) * 37;
    var p_emotes = page * 37;
    var emotes_div = document.getElementById('emoticons');
    var emote_pages_sel = document.getElementById('emote_page');
    var page_num = "";
    //IE11
    if(window.location.hash = !!window.MSInputMethodContext && !!document.documentMode){
        var it = 0;
        var ie11_shit = document.getElementById('ie11_shit');
        var tmp = "";
        var ie11_tmp = "";
        var emoticon11 = new Array();

        ie11_tmp = ie11_shit.innerHTML;
        if(page == 1){
            document.getElementById('previous_emo_p').style.display = 'none';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page > 1 && page < emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page == emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'none';
        }
        emotes_div.innerHTML = '';

        while(it < ie11_tmp.length){
            if(ie11_tmp.charAt(it) == ','){
                emoticon11.push(tmp);
                tmp = "";
            }
            else
                tmp = tmp.concat(ie11_tmp.charAt(it));
            it++;
        }
        while(i < p_emotes && i <= emoticon11.length){
            i++;
            emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
            emoticon11[i].split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon11[i] + '"></button>');
        }
        emotes_div.innerHTML = emotes_div.innerHTML.concat('<div id="ie11_shit" style="display: none;">').concat(ie11_tmp).concat('</div>');
        emote_page = page;
        page_num = page + '_page';
        document.getElementById(page_num).selected = true;
    }
    else{
        if(page == 1){
            document.getElementById('previous_emo_p').style.display = 'none';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page > 1 && page < emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'inline';
        }
        else if(page == emote_pages){
            document.getElementById('previous_emo_p').style.display = 'inline';
            document.getElementById('next_emo_p').style.display = 'none';
        }
        emotes_div.innerHTML = '';
        if(document.selection){//IE8
            while(i < p_emotes && i <= emoticon.length){
                i++;
                emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
                emoticon[i].getElementsByTagName('file')[0].childNodes[0].nodeValue.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + 
                emoticon[i].getElementsByTagName('file')[0].childNodes[0].nodeValue + '"></button>');
            }
            emote_page = page;
            emote_pages_sel.selectedIndex = page;
        }
        else{
            while(i < p_emotes && i <= emoticon.length){
                i++;
                emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
                emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
            }
            emote_page = page;
            page_num = page + '_page';
            document.getElementById(page_num).selected = true;
        }
    }
}

function getPaginateEmoticons(page){
    var emotes_div = document.getElementById('emoticons');
    var emote_pages_sel = document.getElementById('emote_page');
    var i;

    if(document.selection){//IE8
        if(window.XMLHttpRequest)//IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        else//IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.open("GET", "resources/emo_catalog.xml", false);
        xmlhttp.send();
        xmlDocument = xmlhttp.responseXML;
        emoticon = xmlDocument.getElementsByTagName('emoticon');
        emote_pages = Math.floor(emoticon.length / 37);
        emote_page = page;

        for(i = 0; i < 37; i++){
            if(i <= emote_pages)
                emote_pages_sel.options[emote_pages_sel.options.length] = new Option('Page ' + i, i);
            emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
            emoticon[i].getElementsByTagName('file')[0].childNodes[0].nodeValue.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].getElementsByTagName('file')[0].childNodes[0].nodeValue + '"></button>');
        }
        document.getElementById('previous_emo_p').style.display = 'none';
        document.getElementById('loadingIcon').style.display = 'none';
    }
    else{
        function handler(){
            if(this.status == 200 && this.responseXML != null){
                //IE11
                if(window.location.hash = !!window.MSInputMethodContext && !!document.documentMode){
                    emotes_div.innerHTML = '<div id="ie11_shit"></div>';
                    var ie11_shit = document.getElementById('ie11_shit');
                    ie11_shit.style.display = "none";
                    emoticon = this.responseXML.getElementsByTagName('file');
                    for(i = 0; i < emoticon.length; i++){
                        ie11_shit.innerHTML = ie11_shit.innerHTML.concat(emoticon[i].textContent).concat(',');
                    }
                }
                else
                    emoticon = this.responseXML.getElementsByTagName('file');
                emote_pages = Math.floor(emoticon.length / 37);
                emote_page = page;
                for(i = 0; i < 37; i++){
                    if(i <= emote_pages && i >= 1)
                        emote_pages_sel.innerHTML = emote_pages_sel.innerHTML.concat('<option id="' + i + '_page" value="' + i + '">Page ' + i + '</option>');  
                    emotes_div.innerHTML = emotes_div.innerHTML.concat('<button class="emobutton" onclick="insertEmote(document.getElementById(' + i + ').alt);"><img id="' + i + '" alt=":' + 
                    emoticon[i].textContent.split('\\').pop().split('/').pop().split('.').shift() + ':" src="' + emoticon[i].textContent + '"></button>');
                }
                document.getElementById('previous_emo_p').style.display = 'none';
                document.getElementById('loadingIcon').style.display = 'none';
            }
            else{
                // something went wrong
            }
        }
        var client = new XMLHttpRequest();
        client.onload = handler;
        client.open("GET", "resources/emo_catalog.xml");
        client.send();
    }
}