Hi friends,
I have a mystery. Here below a function that loads an image. It happens that the image width and height could not be gathered before executing the openPopImg() function, so I have added a ELSE portion where the pleaseWait() window is popped up, then I do a getImage(imgFleet) again. The problem is that the value of imgFleet in the ELSE portion 'is undefined'. I do not understand why, though it's still a known local variable.
function getImage(imgFleet)
{
var imgX = new Image();
imgX.src = imgFleet;
var imgWidth = imgX.width
var imgHeight = imgX.height;
var picName = imgFleet;
if (imgHeight){
openPopImg(imgFleet,picName,imgWidth,imgHeight);
}
else
{
pleaseWait();
setTimeout('getImage(imgFleet)',5000); // it's here that imgFleet is undefined....
}
}
Code below is only for information
function pleaseWait()
{
text = "<html>\n<head>\n<title>Pop Window</title>\n<body bgcolor='red'>\n";
text += "<center>\n<br>";
text += "<h2>Please Wait...</h2>";
text += "<h5>If the image doesn't appear, click again.</h5>";
text += "</center>\n</body>\n</html>\n";
var window_width=300;
var window_height=100;
var window_left=(screen.availWidth/2)-(window_width/2);
var window_top=(screen.availHeight/2)-(window_height/2);
var window_dimensions="height="+window_height+
",width="+window_width+
",left="+window_left+
",top="+window_top
newWindow = window.open('','newWin',window_dimensions);
newWindow.document.write(text);
setTimeout('closeWin(newWindow)',5000); // delay 5 seconds before closing
}
function closeWin(newWindow)
{
newWindow.close(); // close small window
}
I have a mystery. Here below a function that loads an image. It happens that the image width and height could not be gathered before executing the openPopImg() function, so I have added a ELSE portion where the pleaseWait() window is popped up, then I do a getImage(imgFleet) again. The problem is that the value of imgFleet in the ELSE portion 'is undefined'. I do not understand why, though it's still a known local variable.
function getImage(imgFleet)
{
var imgX = new Image();
imgX.src = imgFleet;
var imgWidth = imgX.width
var imgHeight = imgX.height;
var picName = imgFleet;
if (imgHeight){
openPopImg(imgFleet,picName,imgWidth,imgHeight);
}
else
{
pleaseWait();
setTimeout('getImage(imgFleet)',5000); // it's here that imgFleet is undefined....
}
}
Code below is only for information
function pleaseWait()
{
text = "<html>\n<head>\n<title>Pop Window</title>\n<body bgcolor='red'>\n";
text += "<center>\n<br>";
text += "<h2>Please Wait...</h2>";
text += "<h5>If the image doesn't appear, click again.</h5>";
text += "</center>\n</body>\n</html>\n";
var window_width=300;
var window_height=100;
var window_left=(screen.availWidth/2)-(window_width/2);
var window_top=(screen.availHeight/2)-(window_height/2);
var window_dimensions="height="+window_height+
",width="+window_width+
",left="+window_left+
",top="+window_top
newWindow = window.open('','newWin',window_dimensions);
newWindow.document.write(text);
setTimeout('closeWin(newWindow)',5000); // delay 5 seconds before closing
}
function closeWin(newWindow)
{
newWindow.close(); // close small window
}
Comment