I guess that history.go(-2) was an attempt to go back to image 1 when it is on image 3 (1 - 3 = -2).
However that won't work , as the page never went forwardly or backwardly. Although the image changed, it was always the "same page".
use the following code, and follow the test sequence specified below, you will see what history.go(-2) actually does.
Code:
function switchImage()
{
if(currentImgNumber < numberOfImages)
{
document.imgAdvert.src = ++ currentImgNumber + '.jpeg';
} else if (currentImgNumber == numberOfImages) {
history.go(-2);
}
setTimeout("switchImage()",3000);
}
Steps for testing:
- visit www.cnn.com (this is page 1)
- visit www.abcnews.com (this is page 2)
- visit the testing page (this is page 3, and remains as page 3 while the image changes)
- Wait until you see the last page, wait for 3 more seconds, you will be led back to www.cnn.com