This javascript has the same error in all it's for loops.
The loops are written like this:
// Let's determine the maximum height out of all columns specified
var maxHeight = 0;
for (i = 0; i < divs.length; ++i) {
if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
}
This says "for each value of i from 1 to divs.length+1". ++i means "increment i and then execute the code with the new value of i". This is obviously not what was intended, as Javascript array indexes run from 0 to length-1.
You should have written:
// Let's determine the maximum height out of all columns specified
var maxHeight = 0;
for (i = 0; i < divs.length; i++) {
if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
}
Note: i++ (postincrement) and not ++i (preincrement). This now says "for each value of i from 0 to divs.length".
huh??? it's the <
that cases it to go to divs.length-1
, and has nothing to do with preincrement vs. postincrement. when ++i
or i++
are "by themselves", there's no difference between the two (it only makes a difference when they are used in part of another expression) -- WN
This error causes IE to fall over when viewing old revs of topics.
CC
Huh? Is IE a special case?
Just doing a quick test:
<script type="text/javascript">
//<![CDATA[
var i = 0;
var divs = new Array();
divs[0] = "leftbar";
divs[1] = "main";
// ----
document.write("preincrement" + "<br />");
for (i = 0; i < divs.length; ++i) {
document.write(i + " " + divs[i] + "<br />");
}
// ----
document.write("postincrement" + "<br />");
for (i = 0; i < divs.length; i++) {
document.write(i + " " + divs[i] + "<br />");
}
// ----
document.write("test empty divs list" + "<br />");
divs = new Array();
document.write("preincrement" + "<br />");
for (i = 0; i < divs.length; ++i) {
document.write(i + " " + divs[i] + "<br />");
}
document.write("postincrement" + "<br />");
for (i = 0; i < divs.length; i++) {
document.write(i + " " + divs[i] + "<br />");
}
//]]>
</script>
On the page:
Test:
This doesn't give me any error, and Firefox Javascript console is quiet.
AC
This error causes IE to fall over when viewing old revs of topics. - is this any older revision, or one specific page?
AC
The bug was that on a diff page the div #patternLeftBar does not exist, and the script did not have a check on non existing elements. I've added the check and the bug is gone.
SVN 7479.
AC