I just found a problem with IE9 in how it handles the load event for img tags. With IE8 and earlier if I wanted to perform some JS function after an image loaded I could do something like this:
img = new Image();
img.src = ‘some.jpeg’;
if(img.complete){
somefunc();
} else {
img.attachEvent( “onload”, somefunc );
}
but with IE9 the event will never fire regardless of whether the image file is in the browser cache or not. To fix this you just need to set the img src after attaching the event or reset the img src after attaching the event like so:
img = new Image();
img.src = ‘some.jpeg’;
if(img.complete){
somefunc();
} else {
img.attachEvent( “onload”, somefunc );
img.src = img.src;
}
Hopefully this will help someone else out running into this same problem and encourage the IE team to fix it.
Hi I was wondering if there was a way I could contact you to ask you a few questions about the computer repair field. I’ve been running a computer repair business for a little while now and am confused about a couple of non-tech factors of the business.
Thanks
Is it really a bug? Or a side-effect that we had been previously coding against?
Loosely trying to make sense of the whole thing…
If you set the ‘src’ of the image before you bind to the onload event. Wouldn’t it be possible that the onload event had fired after you set the ‘src’ but before you attached to the event?
Thank you so much! Just saved me couple of hours debugging IE9.
If i were to start my own PC Repair business, what tools and equipment should i start out with besides a toolbox i received as part of my Online PC Repair courses..Is there anything else? Should i have more than one test computer?..Diagnostic PCI Devices etc.?..Extra parts?…..Thanx…Your site is very helpul 🙂
You really don’t need much beyond a few simple hand tools most of which are never needed. Expensive diagnostic equipment is nice but not necessarily because almost all components can be tested by simply swapping them into another system. Extra parts are good to keep around, spare hard drives and power supplies are particularly useful but most customers are understanding if parts have to be ordered.
I would like to note that this problem is not fixed to date, even in the IE10 which is shipped with Windows 8 preview.