为什么当所有其他浏览器(IE7,8,9, FF, Opera和Safari)重复调用img元素的onerror事件时,Chrome只调用一次?
是否有一种方法可以强制Chrome再次重复调用onerror事件?
HTML:
<div id="thisWorks">
this works in Chrome. onerror event is called once.
<img src="http://www.asdfjklasdfasdf.com/bogus1.png"
onerror="fixit(this);"
rsrc="http://eatfrenzy.com/images/success-tick.png" />
</div>
<div id="thisDoesNotWork">
this does not work in Chrome. onerror event is not called twice.
<img src="http://www.asdfjklasdfasdf.com/bogus1.png"
onerror="fixit(this);"
rsrc="http://www.asdfjklasdfasdf.com/bogus2.png|http://eatfrenzy.com/images/success-tick.png" />
</div>
JAVASCRIPT:
function fixit(img)
{
var arrPhotos = img.getAttribute('rsrc').split('|');
// change the img src to the next available
img.setAttribute('src', arrPhotos.shift());
// now put back the image list (with one less) into the rsrc attr
img.setAttribute('rsrc', arrPhotos.join('|'));
return true;
}
编辑:根据@Sunil D.的评论,Chrome在初始fiddle示例中由于www.asdfjklasdfasdf.com
的无效域名未发出新的查询,因此我已经改变了域名以匹配成功的图片,但是文件名不同,所以仍会出现404错误。这证明了无效的域名并非导致Chrome在第二次尝试时退出的原因。
编辑:更新了fiddle并删除了使用jquery来简化操作和排除可能性。