I'm trying to write a function to determine whether or not an image exists.
Most people recommend setting the onload event handler. That works like a
charm except that side-effective actions seem to be impossible. I can, as
nearly as I can tell, run alert and opera.postError (I test on IE, firefox,
and opera by the way). I've tried using the 'this' while in the event
handler, setting this.name, test.name, window.document .getElementById (test's
id).name. I just can't seem to find any means of using side effects inside
the event handler.
Below are several examples of things I've tried so far:
----------------------------------------
var test = new Image();
var id = imageUtils_getU niqueId();
alert("before-> " + window.document .body.childNode s.length);
test.id = id;
test.name = id;
test.onload = function () {window.documen t.body.appendCh ild(test);};
test.src = url;
while(!test.com plete){}
alert("after-> " + window.document .body.childNode s.length);
alert: before-> 12
alert: after-> 12
yet, the image still shows up on the page...
----------------------------------------
----------------------------------------
var test = new Image();
var didSucceed = false;
test.onload = function () {
didSucceed = true;
alert("load-> " + test.height);
};
test.src = url;
alert("post-> " + test.height);
return didSucceed;
alert: load-> 302
alert: post-> 0
returns false;
----------------------------------------
----------------------------------------
var test = new Image();
test.src = url;
while(!test.com plete){}
alert(test.heig ht);
alert: 0
----------------------------------------
----------------------------------------
var test = new Image();
test.id = imageUtils_getU niqueId();
window.document .body.appendChi ld(test);
test.src = url;
while(!test.com plete){}
alert(test.heig ht);
alert: 0
----------------------------------------
Any assistance would be greatly appreciated.
Thank you,
Harrison
--
Harrison Caudill BS BS | .^ www.hypersphere.org
Computer Science & Physics Graduate | | Me*Me=1
Georgia Institute of Technology | v' I'm just a normal guy