img load goes into infinite loop in IE7 and IE8
I have the following code in my page, which works fine on all browsers (even on IE9), but not on IE7 and IE8:
$.each($('.cic img'), function(index, value) {
$(this).load(function() {
// infinite loop here in IE7 and IE8
});
});
The HTML is:
<div class="cic">
<img wicket:id="image1" class="image1" />
</div>
...
<div class="cic">
<img wicket:id="image2" class="image2" />
</div>
The reason for this is that on IE7 and IE8 the load function goes into an infinite loop and I end up with the message: 'This page became unresponsive due to a long running script'.
EDIT: Changing the the selector to $('.cic img').each() did not help. I also confirmed that loadImageCropper() is not the cause of the problem. I also typed $('.cic img').lenght before the above script, and it returned 2, which 开发者_如何转开发is correct.
The above script and HTML are being loaded with AJAX.
I'll appreciate any help! Thank you in advance!
As with the script element, IE8 and under fire legacy readyStateChange events rather than standard load events for img src updates, so the load event masks the fact that the event is not recognized. The solution is to fork the code before the event binding:
function imageSwap()
{
var $img = $('.cic img');
if(!!document.addEventListener)
{
$img.on("load", loadTest)
}
else
{
$img.get(0).attachEvent("onreadystatechange", loadTest);
}
function loadTest(event)
{
$img.show();
}
}
精彩评论