开发者

Internet Explorer dies trying to load javascript array on initialisation?

in my javascript I load up an array based upon the HTML which has already produced. In Firefox this works perfectly, but in Internet Explorer 7 the page hangs for approximately several minutes.

I can't see why it takes so long to do something Firefox has no problem with?

I开发者_开发技巧mageHTMLContainer just acts like a dictionary storing inner html.

var ImageHTMLContainer = [];

addLoadEvent(init);

function init() {

    var NumOfRows = parseInt(DID("NumRows").innerHTML);
    var NumOfCols = parseInt(DID("NumCols").innerHTML);
    var i;
    var j;

    for (i = 0; i < NumOfRows; i++) {
        ImageHTMLContainer["Row" + i.toString()] = DID("Row" + i).innerHTML;
        for (j = 0; j < NumOfCols; j++) {
            ImageHTMLContainer["Row" + i.toString() + "Col" + j.toString()] = DID("Row" + i + "Col" + j).innerHTML;
        }
    }
}


ie7's js engine is a lot older and slower than the one in firefox.

You have a loop within a loop that reads innerHTML - don't do that, it is probably the very least efficient way you can do what you are doing.

Have you considered loading your data via xml or json instead of initializing your javascript data via the rendered DOM?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜