In IE8, the variable widths looks like [null, 600, 800, 600] and will be [600, 800, 600] by widths.splice(i, 1);.
But the variable l is still 4. So i will refer to the out of range.
The below code can fix this issue.
function getViewportWidthInCssPixels() {
...
for (; i < l; i++) {
// If not a number remove it
if (isNaN(widths[i])) {
widths.splice(i, 1);
i--;
l--; // need decrement
}
}
...
}
In IE8, the variable
widths
looks like[null, 600, 800, 600]
and will be[600, 800, 600]
bywidths.splice(i, 1);
. But the variablel
is still4
. Soi
will refer to the out of range.The below code can fix this issue.