posted 6/21/2013 by Raghav Khunger
While working with "load" method of image I noticed it was not working successfully in IE. I was using the following code:
$('<img/>').attr('src', '<myimageurl>').load(function() { alert('Image is successfully loaded'); }).error(function() { alert('You have broken image!'); });
i.e Setting the src, binding load and then error methods. The above code was working fine in Chrome and FF but in IE "load" method was not getting fired.
Cause:If the image you are setting as src is in the browser cache, the load event will be fired immediately. If there is no "load" handler attached at this moment we can miss the "load" handler attached later.
Solution:Set the src of image after the load handler has been attached i.e after writing the code in this way my issue got fixed.:
$('<img/>').load(function() { alert('Image is successfully loaded'); }).error(function() { alert('You have broken image!'); }).attr('src', '<myimageurl>');
What kind of email newsletter would you prefer to receive from CodeAsp.Net? 18